Skip to content

Type of ReflectionEnum::getBackingType() should/could be narrowed after ::isBacked() #10167

@RobertMe

Description

@RobertMe

Bug report

The formal return value of ReflectionEnum::getBackingType() is ?ReflectionNamedType. But it will always return ReflectionNamedType (i.e.: be non-null) for backed enums. So when a ReflectionEnum::isBacked condition is applied the type could/should be narrowed.

Code snippet that reproduces the problem

https://phpstan.org/r/6708f7db-5547-47c6-aa37-38dc5974a1a4

Expected output

Type could/should be just ReflectionNamedType (but is ReflectionNamedType|null).

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions