(PHP 8 >= 8.1.0)
ReflectionEnum::getCase — Returns a specific case of an Enum
Returns the reflection object for a specific Enum case by name. If the requested case is not defined, a ReflectionException is thrown.
name
The name of the case to retrieve.
An instance of ReflectionEnumUnitCase or ReflectionEnumBackedCase, as appropriate.
Example #1 ReflectionEnum::getCase() example
<?phpenum Suit{ case Hearts; case Diamonds; case Clubs; case Spades;}$rEnum = new ReflectionEnum(Suit::class);$rCase = $rEnum->getCase('Clubs');var_dump($rCase->getValue());?>
The above example will output:
enum(Suit::Clubs)