Skip to content

::class syntax equivalence with instanceof #9542

@Seb33300

Description

@Seb33300

Bug report

PHPStan is able to recognize a condition using instanceof syntax (eg: if ($foo instanceof Bar)), but not a condition using the ::class syntax (eg: if ($foo::class === Bar::class)) to determine the object class.

This result in that break in EasyAdmin project: https://github.com/EasyCorp/EasyAdminBundle/pull/5813/files#r1247414831

Code snippet that reproduces the problem

https://phpstan.org/r/0c84ecb2-1b23-42a8-9161-a32f7096c5b8
https://phpstan.org/r/05f9613a-d9cf-4321-986e-247723efcbb9

Expected output

if ($foo instanceof Bar) should be equivalent to if ($foo::class === Bar::class)

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions