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 for empty on non-empty-string #7199

Closed
oliverklee opened this issue May 7, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1595
Closed

False positive for empty on non-empty-string #7199

oliverklee opened this issue May 7, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1595
Labels
Milestone

Comments

@oliverklee
Copy link
Sponsor

Bug report

empty() in PHP is evil and behaves in mysterious ways. Particularly, as it basically is a check for truthy-ness, it considers the string "0" to be empty. That means that any variable/parameter that is a non-empty-string can still lead to empty($var) to be empty as well.

Code snippet that reproduces the problem

https://phpstan.org/r/5f809ad5-cee9-423c-b7aa-9ec2d432793a

Expected output

no error

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

PHPStan still is one of my favorite gamified activities, and it helps me improve the code of my TYPO3 extensions and the TYPO3 core.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 9, 2022
@phpstan-bot
Copy link
Contributor

@oliverklee After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-10: Variable $string in empty() always exists and is not falsy.
+No errors

staabm added a commit to staabm/phpstan-src that referenced this issue Aug 6, 2022
staabm added a commit to staabm/phpstan-src that referenced this issue Aug 6, 2022
ondrejmirtes pushed a commit to phpstan/phpstan-src that referenced this issue Aug 6, 2022
@oliverklee
Copy link
Sponsor Author

Thanks! ❤️

@github-actions
Copy link

github-actions bot commented Sep 8, 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 Sep 8, 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.

3 participants