Skip to content

require_once makes the plugin 'forget' #1982

Open
@t0mm1e

Description

@t0mm1e
Subject Details
Plugin PHP Inspections (EA Ultimate)
Language level 8.4

Question
The plugins seems to forget the types of the variables declared before a require_once.
Flor example:

<?php

declare(strict_types=1);

function get_test(): array|false {
	return [
		'TEST'	=> 'test',
		'TOST'	=> 'tost',
		'TIST'	=> 'tist',
	];
}

function test(): void {
	if (!($test = get_test())) {
		return;
	}

	echo $test['TEST'], "\n";

	require_once 'huh.php';

	echo $test['TEST'], "\n";
}

Above examplew show no problem with the first echo, but de second echo gets marked by the PHP Inspections plugin with: [EA] '$test' may not support offset operations (or its type not annotated properly: [bool, array]).

Am I doing something wrong (apart from doing requires inside code, which I like to do, because it groups the require with the code that requires the require, instead of ending up with 30 requires at the top of a function or file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions