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

Missing potential false on DateTime::modify #4927

Closed
yann-eugone opened this issue Apr 30, 2021 · 6 comments · Fixed by phpstan/phpstan-src#1267
Closed

Missing potential false on DateTime::modify #4927

yann-eugone opened this issue Apr 30, 2021 · 6 comments · Fixed by phpstan/phpstan-src#1267
Labels
Milestone

Comments

@yann-eugone
Copy link

yann-eugone commented Apr 30, 2021

Bug report

Both DateTime::modify & DateTimeImmutable::modify can return false, but got following message when testing result :

Strict comparison using === between DateTimeImmutable and false will always evaluate to false.
Strict comparison using === between DateTime and false will always evaluate to false.

I found #1934 which is about almost the same thing, but somehow the issue get closed.

Code snippet that reproduces the problem

https://phpstan.org/r/3b587421-aa5b-4c3f-ac48-7b5c20e1d61c

https://3v4l.org/sTN7A

Expected output

These 2 methods should consider that the return type is potentially false, as documented here :

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Apr 30, 2021
@pbourdet
Copy link

Hello, ran into this issue as well on version 1.5.2

@VincentLanglet
Copy link
Contributor

This can be fixed by changing this line https://github.com/phpstan/phpstan-src/blob/1.6.x/resources/functionMap.php#L1607

But having an error because $dateTime->modify('+1 year') might be false will be disturbing.
So IMHO, it would required to add a dynamicReturnTypeExtension

@VincentLanglet
Copy link
Contributor

Will be fixed by phpstan/phpstan-src#1267

@phpstan-bot
Copy link
Contributor

@yann-eugone After the latest commit in 1.7.x, PHPStan now reports different result with your code snippet:

@@ @@
-3: Strict comparison using === between DateTimeImmutable and false will always evaluate to false.
-6: Strict comparison using === between DateTime and false will always evaluate to false.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#1267

@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

Successfully merging a pull request may close this issue.

5 participants