You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
while-true-try: Variable might not be defined #10245
Did PHPStan help you today? Did it make you happy in any way?
I think I cannot count the amount of issues that didn't reach production thanks to PHPStan. It also helps a lot when reviewing code as I can focus on the core logic instead of the possible mistakes here and there.
@@ @@-PHP 8.0 – 8.3 (2 errors)+PHP 8.0 – 8.3 (3 errors)
==========
+ 6: Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.
18: Dumped type: mixed
18: Variable $a might not be defined.
-PHP 7.2 – 7.4 (3 errors)+PHP 7.2 – 7.4 (4 errors)
==========
+ 6: Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.
15: Non-capturing catch is supported only on PHP 8.0 and later.
18: Dumped type: mixed
18: Variable $a might not be defined.
Full report
PHP 8.0 – 8.3 (3 errors)
Line
Error
6
Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.
18
Dumped type: mixed
18
Variable $a might not be defined.
PHP 7.2 – 7.4 (4 errors)
Line
Error
6
Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.
15
Non-capturing catch is supported only on PHP 8.0 and later.
Activity
donquixote commentedon Aug 22, 2024
Similar case without try/catch: https://phpstan.org/r/2bb8d587-d9cb-4d11-b164-d6133dc87731
The same happens with
for(;;).The reason to use
while (true)orfor (;;)would be if the entry point of the loop is the wrong place for an exit condition.phpstan-bot commentedon Sep 30, 2024
@homersimpsons After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.3 (3 errors)
Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.Dumped type: mixedVariable $a might not be defined.PHP 7.2 – 7.4 (4 errors)
Function produceInt() has Exception in PHPDoc @throws tag but it's not thrown.Non-capturing catch is supported only on PHP 8.0 and later.Dumped type: mixedVariable $a might not be defined.Add regression tests for #11545, #10245, #5919, #5477
Add regression test for #10245
Add regression tests for #11545, #10245, phpstan#5919, phpstan#5477
Add regression tests for #11545, #10245, phpstan#5919, phpstan#5477
phpstan-bot commentedon Mar 3, 2026
Closed via merging phpstan/phpstan-src#5118
github-actions commentedon Apr 4, 2026
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.