phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
592 stars 46 forks source link

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

Closed Wirone closed 5 months ago

Wirone commented 5 months ago

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.

ondrejmirtes commented 5 months ago

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.

github-actions[bot] commented 4 months ago

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.