Skip to content

isset/empty wrongly considered as callable #6014

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

Closed
villfa opened this issue Nov 16, 2021 · 6 comments
Closed

isset/empty wrongly considered as callable #6014

villfa opened this issue Nov 16, 2021 · 6 comments
Labels
Milestone

Comments

@villfa
Copy link
Contributor

villfa commented Nov 16, 2021

Bug report

empty() and isset() are considered as callable by PHPStan while they're not.

Code snippet that reproduces the problem

https://3v4l.org/iMgPt

<?php
var_dump(is_callable('empty')); // bool(false)
var_dump(is_callable('isset')); // bool(false)

https://phpstan.org/r/c8e58374-a244-41c8-927c-1905a945389e

Call to function is_callable() with 'empty' will always evaluate to true.
Call to function is_callable() with 'isset' will always evaluate to true.

Expected output

Call to function is_callable() with 'empty' will always evaluate to false.
Call to function is_callable() with 'isset' will always evaluate to false.

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

PHPStan is an awesome tool. Thanks for your work!

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Nov 16, 2021
@ondrejmirtes
Copy link
Member

This is interesting, I'd love to know what monster and where defined these as existing functions, but I'm too busy to debug that now :)

@villfa
Copy link
Contributor Author

villfa commented Nov 16, 2021

For the record, the problem also concerns other reserved keywords.
Here the exhaustive list:

  • __halt_compiler
  • empty
  • eval
  • exit
  • isset
  • print
  • unset

(die, include, list, and more, are fine)

@phpstan-bot
Copy link
Contributor

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

@@ @@
-3: Call to function is_callable() with 'empty' will always evaluate to true.
-4: Call to function is_callable() with 'isset' will always evaluate to true.
+3: Call to function is_callable() with 'empty' will always evaluate to false.
+4: Call to function is_callable() with 'isset' will always evaluate to false.
Full report
Line Error
3 Call to function is_callable() with 'empty' will always evaluate to false.
4 Call to function is_callable() with 'isset' will always evaluate to false.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@08f3e2d

@villfa
Copy link
Contributor Author

villfa commented Nov 16, 2021

Thank you!

@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 Dec 18, 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

3 participants