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

Unset detection with try/catch does not take into account origin of the exception. #3822

Closed
frankdejonge opened this issue Sep 2, 2020 · 5 comments

Comments

@frankdejonge
Copy link

Bug report

When an unset call is placed after a call where an exception can originate from, the catch clause is not able to use the variable, even though the unset call can never be made.

Code snippet that reproduces the problem

https://phpstan.org/r/abf2e5c9-90a3-40fc-9979-6d19255e7c67

Expected output

No errors were found

@ondrejmirtes
Copy link
Member

This is very similar to other issues grouped in this milestone: https://github.com/phpstan/phpstan/milestone/11

@ondrejmirtes ondrejmirtes added this to the Exception tracking milestone Sep 2, 2020
@phpstan phpstan deleted a comment from phpstan-bot Mar 3, 2021
@phpstan-bot
Copy link
Contributor

@frankdejonge PHPStan now reports different result with your code snippet:

@@ @@
+PHP 7.3 – 8.0 (1 error)
+==========
+
+31: Variable $body might not be defined.
+
+PHP 7.1 – 7.2 (2 errors)
+==========
+
+30: Caught class JsonException not found.
 31: Variable $body might not be defined.
Full report

PHP 7.3 – 8.0 (1 error)

Line Error
31 Variable $body might not be defined.

PHP 7.1 – 7.2 (2 errors)

Line Error
30 Variable $body might not be defined.
31 Variable $body might not be defined.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-31: Variable $body might not be defined.
+PHP 7.3 – 8.0
+==========
+
+No errors
+
+PHP 7.1 – 7.2 (1 error)
+==========
+
+30: Caught class JsonException not found.
Full report

PHP 7.3 – 8.0

No errors

PHP 7.1 – 7.2 (1 error)

Line Error
30 Caught class JsonException not found.

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#481

@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 Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants