Skip to content

phpstan thinks is_subclass_of always returns false if the first argument is a string #6697

@mind-bending-forks

Description

@mind-bending-forks

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions