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

False positive with try-catch #1597

Closed
enumag opened this issue Nov 9, 2018 · 7 comments
Closed

False positive with try-catch #1597

enumag opened this issue Nov 9, 2018 · 7 comments

Comments

@enumag
Copy link
Contributor

enumag commented Nov 9, 2018

Summary of a problem or a feature request

PHPStan assumes that $date will be \DateTime instance in the catch block which may not be true.

Code snippet that reproduces the problem

https://phpstan.org/r/16f4221ff88c24829994a285304c13f8

Expected output

no error

@ondrejmirtes ondrejmirtes added this to the Exception tracking milestone Nov 15, 2018
@adaamz
Copy link
Contributor

adaamz commented Jul 13, 2019

This looks like it is fixed https://phpstan.org/r/38dd3f24-0b99-445e-b6ec-8162fe1950ea
but I don't get why your Expected output is NO ERROR... there is error, see https://3v4l.org/4ooeP

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 13, 2019 via email

@phpstan-bot
Copy link
Contributor

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

@@ @@
-9: Parameter #1 $unixtimestamp of method DateTime::setTimestamp() expects int, string given.
+8: Call to function is_numeric() with ''|DateTime will always evaluate to false.
Full report
Line Error
8 Call to function is_numeric() with ''

@phpstan-bot
Copy link
Contributor

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

@@ @@
-9: Parameter #1 $unixtimestamp of method DateTime::setTimestamp() expects int, string given.
+8: Call to function is_numeric() with '' will always evaluate to false.
Full report
Line Error
8 Call to function is_numeric() with '' will always evaluate to false.

@enumag
Copy link
Contributor Author

enumag commented Mar 27, 2021

I think the result is correct now. Thank you @ondrejmirtes! I'll leave it open for now in case you want to add a regression test but feel free to close it if not.

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#481

I'll add the regression test later in a batch.

@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

4 participants