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

Incorrect "Variable might not be defined" with a try/catch #3302

Closed
VincentLanglet opened this issue May 14, 2020 · 3 comments
Closed

Incorrect "Variable might not be defined" with a try/catch #3302

VincentLanglet opened this issue May 14, 2020 · 3 comments
Labels

Comments

@VincentLanglet
Copy link
Contributor

Bug report

Code snippet that reproduces the problem

I have an error with
https://phpstan.org/r/b33506ff-66aa-45c9-8d81-db3fa4227b0b

The following code is working https://phpstan.org/r/f04ed63c-88c0-4169-9ed0-97b1f92daa92
But when I throw an exception inside the try, it's not working anymore.

Expected output

No error

@ondrejmirtes
Copy link
Member

PHPStan does not yet check what exceptions can be thrown out of the try block. If you throw something that isn't an exception, the variable might not exist: https://3v4l.org/63iZP

Unfortunately PHPStan doesn't get that catch (\Throwable $e) makes it exhaustive and fails the same way https://phpstan.org/r/bdb7b5cd-d173-47e3-a75c-1ff2b67d1a7d but it's a pretty minor issue as you can easily rewrite the code.

@ondrejmirtes ondrejmirtes added this to the Exception tracking milestone May 14, 2020
@ondrejmirtes ondrejmirtes removed this from the Exception tracking milestone Mar 27, 2021
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@00c81b1

@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 30, 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

2 participants