Skip to content

value-of<BackedEnum> would be cool to have #6775

@NLthijs48

Description

@NLthijs48

Feature request

Currently value-of<BackedEnum> gives an error like PHPDoc tag @param for parameter $countryName contains unresolvable type., it would be nice to have support for this though.
Playground example: https://phpstan.org/r/8369e6e4-b6d7-4210-9a5d-92b754e0f2d7

Additionally PHPStan does not error on types that have this as array key: array<value-of<BackedEnum>, bool>, which means that it silently accepts incorrect code in this case (key-of has the same issue in this case, I guess that should just not be allowed though).
Playground example: https://phpstan.org/r/50d372e7-f7bf-49a2-8456-2eb89d97b7bc

Declaring array<value-of<BackedEnum>> does at least correctly warn about an unresolvable type, so that case is not silent.

Until a time that enums can be used as array keys it would be nice to support this to enforce correct code.
Let me now what you think about this use-case.

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

Today I used enums together with match, and phpstan gives a nice error when a case is forgotten in match if there is no default defined, which is great!

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