I have an application where I define some variables in a file (a.php), then include this from another file (b.php). PHPStan is complaining about possibly undefined variables.
Simplified example:
a.php:
$config['foo'] = 'bar';
b.php:
<?php
require 'a.php';
//new SlimApp($config)->run();
echo $config;
PHPStan says:
------ ----------------------------------------
Line b.php
------ ----------------------------------------
:6 Variable $config might not be defined.
------ ----------------------------------------
Also: I don't know why but if I remove the <?php line at the beginning of b.php, the warning goes away.
How can I have PHPStan realize that $config is actually defined?
Btw I am aware of this question. It is not the same problem as I am explicitly including the file where the variable is defined.
requireorincludeanything, it just relies on the variables being defined elsewhere. PHPStan cannot know that. This case is different./** @var array $config */at the top of the file, see: github.com/phpstan/phpstan/issues/5815