vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 659 forks source link

Calling language construct as function with leading backslash #8529

Open StarringLara opened 1 year ago

StarringLara commented 1 year ago

In PHP, many language constructs commonly look like functions when called, even though they are not functions and really are language constructs. If you call these language constructs with a leading \ as if using a fully qualified name for the function call, PHP will throw a "Call to undefined function" exception. In some cases, Psalm catches these calls to undefined functions, and in other cases it does not.

https://psalm.dev/r/cbd5c874d3

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/cbd5c874d3 ```php
orklah commented 1 year ago

Interesting!

The difference is that unset, isset, empty and print are listed in Callmap.php while include, require and die are not.

Considering we have special handling for about all of those, we don't get to the point where Psalm will have to check if the function exists, but if you add "\", Psalm special handling doesn't seem to trigger (which is coherent) and then it goes to check if we actually know the function (and we only do on some of those).

If you want, you could try dropping unset, isset, empty and print from the Callmap file to see if something break (I don't expect to)