phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan

Repository from Github https://github.comphpstan/phpstan-strict-rulesRepository from Github https://github.comphpstan/phpstan-strict-rules

False positive "Variable might not be defined" after `for` loop

Wirone opened this issue · comments

I believe strict rules falsely report this. Assignment is always done, and then condition is checked so it can escape the loop early, but $i is there, right? This is the fix, but it does not look good to move initial assignments before the for loop.

This is a feature, not a bug of strict-rules. You can turn it off with this setting https://phpstan.org/config-reference#pollutescopewithloopinitialassignments

phpstan-strict-rules mimics how other stricter languages act with loop-scoped variables.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.