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

Dead catch - DivisionByZeroError when divisor is dynamic #6349

Closed
gbirke opened this issue Jan 12, 2022 · 3 comments
Closed

Dead catch - DivisionByZeroError when divisor is dynamic #6349

gbirke opened this issue Jan 12, 2022 · 3 comments
Labels
Milestone

Comments

@gbirke
Copy link

gbirke commented Jan 12, 2022

Bug report

I have code that gets a divisor out of an array that might or might not exist or might be zero. I'm wrapping that with a try/catch block checking for DivisionByZeroError, but apparently PHPStan doesn't "see" that there is a division occurring with a dynamic divisor.

Code snippet that reproduces the problem

https://phpstan.org/r/ece3fd89-f67b-44ec-9e6a-b7b5c1b77b0e

Expected output

No output.

Did PHPStan help you today? Did it make you happy in any way?

Today, PHPStan has helped me to detect unused properties, making my classes leaner and my code more readable. Thank you!

@staabm
Copy link
Contributor

staabm commented Jan 13, 2022

Wouldn't your code be easier to read if you check the divisor beforehand?

That way you could also get rid of the try/catch

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#1280

@github-actions
Copy link

github-actions bot commented Jun 5, 2022

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 Jun 5, 2022
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