Skip to content

enum_exists method should infer variable as class-string<UnitEnum> #10169

@jdecool

Description

@jdecool

Bug report

Consider this code:

function getEnumValue(string $enumFqcn, string $name): mixed {
    if (enum_exists($enumFqcn)) {
        return (new \ReflectionEnum($enumFqcn))->getCase($name)->getValue();
    }

    return null;
}

The $enumFqcn should be considered as class-string<UnitEnum> under the if statement.

Code snippet that reproduces the problem

https://phpstan.org/r/5bab6187-d8c9-40fb-a8e4-9bf830af3075

Expected output

No error expected.

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