-
-
Notifications
You must be signed in to change notification settings - Fork 947
Conditionally defined variables flagged as undefined #8212
Copy link
Copy link
Closed
phpstan/phpstan-src
#1950Labels
Milestone
Description
Bug report
This is the example of conditionally defined variables from:
https://phpstan.org/writing-php-code/solving-undefined-variables
Despite the documentation saying that PHPStan understands this case, it doesn't actually appear to. The snippet itself has the problem that $foo is undefined but if it's set to a indeterminate value than $var will be flagged as undefined (if the level is at least 1). Note that if $foo is determined to be truthy then no error is produced.
Code snippet that reproduces the problem
Expected output
Expect that this is not flagged because var is defined any time it is not referenced.
Reactions are currently unavailable