-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
phpstan/phpstan-src
#96Labels
Milestone
Description
Bug report
PHPStan does not detect an array index variable being overwritten between 2 nested if statements.
Code snippet that reproduces the problem
$tokens = $_GET;
$lastContent = 'a';
if ($tokens[$lastContent]['code'] === 1
|| $tokens[$lastContent]['code'] === 2
) {
$lastContent = 'b';
if ($tokens[$lastContent]['code'] === 3) {
echo "what?";
}
}https://phpstan.org/r/b14bbcfb-cb91-4cec-a4ef-24b452a7aaf3
In this case the index $lastContent is overwritten with 'b', so PHPStan cannot know what is being compared here.
Actual output
+-------------------------------------------------------------------------------------+
| Line | test.php |
+-------------------------------------------------------------------------------------+
| 10 | Strict comparison using === between 1|2 and 3 will always evaluate to false. |
+-------------------------------------------------------------------------------------+
[ERROR] Found 1 error
Expected output
No output because the example is correct.
Reactions are currently unavailable