Skip to content

class-string inference not followed through is_a() #2799

@jbafford

Description

@jbafford

Bug report

When iterating an array<string, class-string<SomeBaseClass>>, phpstan fails to use that type information across an is_a() call to a call on a method of that class.

In the provided example, phpstan reports a call to an undefined method, but the method clearly exists because the object has been checked to be a member of that type.

Code snippet that reproduces the problem

https://phpstan.org/r/9b1cfac7-fbbf-4a07-ab76-ca149e7c04c6

Expected output

Since $class is a class-string<Base>, and is_a($obj, $class), $obj must be a Base, and therefore has the getId() method and should not error.

Alternatively: since is_a($obj, $class), and $class == Foo:class, $class is a Foo, which has a getId().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions