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

Incorrectly assuming int has strlen 0 without strict types #5350

Closed
schlndh opened this issue Jul 21, 2021 · 4 comments · Fixed by phpstan/phpstan-src#617
Closed

Incorrectly assuming int has strlen 0 without strict types #5350

schlndh opened this issue Jul 21, 2021 · 4 comments · Fixed by phpstan/phpstan-src#617
Labels
Milestone

Comments

@schlndh
Copy link

schlndh commented Jul 21, 2021

Bug report

Since version 0.12.93 (it does not happen in 0.12.92) phpstan incorrectly assumes that strlen of an integer is 0 when called from a file without declare(strict_types=1). Casting the integer to string fixes the problem.

Code snippet that reproduces the problem

https://phpstan.org/r/29a373ea-907e-44a5-a426-069ce03a5662

Expected output

Comparison operation "<" between 0 and 3 is always true. should not be reported.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 21, 2021
@phpstan-bot
Copy link
Contributor

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

@@ @@
 7: Comparison operation "<" between 0 and 3 is always true.
-7: Parameter #1 $string of function strlen expects string, int given.
+7: Parameter #1 $string of function strlen expects string, int<0, 10000> given.
Full report
Line Error
7 Comparison operation "<" between 0 and 3 is always true.
7 Parameter #1 $string of function strlen expects string, int<0, 10000> given.

@phpstan-bot
Copy link
Contributor

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

@@ @@
 9: Expected type int, actual: 0
-9: Parameter #1 $string of function strlen expects string, int given.
+9: Parameter #1 $string of function strlen expects string, int<0, 10000> given.
Full report
Line Error
9 Expected type int, actual: 0
9 Parameter #1 $string of function strlen expects string, int<0, 10000> given.

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