ReflectionEnum::getCase
(PHP 8 >= 8.1.0)
ReflectionEnum::getCase — Returns a specific case of an Enum
Beschreibung
Returns the reflection object for a specific Enum case by name. If the requested case is not defined, a ReflectionException is thrown.
Parameter-Liste
-
name
-
The name of the case to retrieve.
Rückgabewerte
An instance of ReflectionEnumUnitCase or ReflectionEnumBackedCase, as appropriate.
Beispiele
Beispiel #1 ReflectionEnum::getCase() example
<?php
enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
$rEnum = new ReflectionEnum(Suit::class);
$rCase = $rEnum->getCase('Clubs');
var_dump($rCase->getValue());
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
enum(Suit::Clubs)
Siehe auch
- Enumerations
- ReflectionEnum::getCases() - Returns a list of all cases on an Enum
- ReflectionEnum::hasCase() - Checks for a case on an Enum
- ReflectionEnum::isBacked() - Determines if an Enum is a Backed Enum