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
A exception thrown is swallowed when the finally block contains a return.
I would expect a error regarding the thrown exception will be swallowed by the php runtime.
today we debugged a class and realized that our exceptions won't get thrown because of such a "finally-return".. its really suprising
@@ @@- 4: Function a() has no return typehint specified.+ 4: Function a() has no return type specified.
6: This return is overwritten by a different one in the finally block below.
7: Dead catch - Exception is never thrown in the try block.
10: The overwriting return is on this line.
Full report
Line
Error
4
Function a() has no return type specified.
6
This return is overwritten by a different one in the finally block below.
7
Dead catch - Exception is never thrown in the try block.
Activity
ondrejmirtes commentedon Sep 13, 2021
There's already a rule for multiple
returns with finally: https://phpstan.org/r/6cbd1e9b-56e2-40fb-9945-26f9c715caf0We could apply it too to "this always thrown exception is shadowed by this
returninfinally" but I think it's a very rare situation.staabm commentedon Sep 13, 2021
experienced it 2 times within the last week. I will see whether I can provide a patch
phpstan-bot commentedon Sep 16, 2021
@staabm After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
Full report
Function a() has no return type specified.phpstan-bot commentedon Sep 16, 2021
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
Full report
Function a() has no return type specified.This return is overwritten by a different one in the finally block below.Dead catch - Exception is never thrown in the try block.The overwriting return is on this line.ondrejmirtes commentedon Sep 16, 2021
Implemented: phpstan/phpstan-src@24c1eb4 + phpstan/phpstan-src@c362fc5
github-actions commentedon Oct 18, 2021
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.