-
-
Notifications
You must be signed in to change notification settings - Fork 947
phpstan thinks is_subclass_of always returns false if the first argument is a string #6697
Copy link
Copy link
Closed
Labels
Milestone
Description
Bug report
phpstan thinks is_subclass_of always returns false if the first argument is a string. If phpstan can't resolve the strings to specific classes in the code base, and so can't determine itself whether is_subclass_of is true or false, it should assume the output is bool, not false.
This clearly has overlaps with (and may even duplicate one or more of) issues #6305, #5369, #3979 and #2755, but my case was dealing with the first argument being a string specifically.
Code snippet that reproduces the problem
https://phpstan.org/r/e4ead7a9-f323-4dbe-af78-ac8a69e518eb
$result = \is_subclass_of( '\\My\\Namespace\\MyClass', '\\My\\Namespace\\MyBaseClass', true);Expected output
No error reported by phpstan. \My\Namespace\MyClass and \My\Namespace\MyBaseClass are unknown to it, and this call to is_subclass_of is valid.
Did PHPStan help you today? Did it make you happy in any way?
Yes. It has helped me squash several potential bugs already today.
Reactions are currently unavailable