Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report swallowed exception #5627

Closed
staabm opened this issue Sep 13, 2021 · 6 comments
Closed

report swallowed exception #5627

staabm opened this issue Sep 13, 2021 · 6 comments

Comments

@staabm
Copy link
Contributor

staabm commented Sep 13, 2021

Feature request

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

https://3v4l.org/OiVkG#v7.4.23
https://phpstan.org/r/8685c7b2-5a0e-4fbb-9e46-dfcca31559b1

@ondrejmirtes
Copy link
Member

There's already a rule for multiple returns with finally: https://phpstan.org/r/6cbd1e9b-56e2-40fb-9945-26f9c715caf0

We could apply it too to "this always thrown exception is shadowed by this return in finally" but I think it's a very rare situation.

@staabm
Copy link
Contributor Author

staabm commented Sep 13, 2021

think it's a very rare situation.

experienced it 2 times within the last week. I will see whether I can provide a patch

@phpstan-bot
Copy link
Contributor

@staabm After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-4: Function a() has no return typehint specified.
+4: Function a() has no return type specified.
Full report
Line Error
4 Function a() has no return type specified.

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
- 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.
10 The overwriting return is on this line.

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src@24c1eb4 + phpstan/phpstan-src@c362fc5

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants