ReflectionEnum::getCase
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.1.0)
Returns a specific case of an Enum
Description
ReflectionEnum::getCase(string $name): ReflectionEnumUnitCase
Returns the reflection object for a specific Enum case by name. If the requested case is not defined, a ReflectionException is thrown.
Parameters
nameThe name of the case to retrieve.
Return Values
An instance of ReflectionEnumUnitCase or ReflectionEnumBackedCase, as appropriate.
Examples
ReflectionEnum::getCase example
php
<?php
enum 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:
output
enum(Suit::Clubs)See Also
- Enumerations
ReflectionEnum::getCasesReflectionEnum::hasCaseReflectionEnum::isBacked