ReflectionEnum::getCases

(PHP 8 >= 8.1.0)

ReflectionEnum::getCasesReturns a list of all cases on an Enum

Beschreibung

public ReflectionEnum::getCases(): array

An Enum may contain zero or more cases. This method retrieves all defined cases, in lexical order (that is, the order they appear in the source code).

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

An array of Enum reflection objects, one for each case in the Enum. For a Unit Enum, they will all be instances of ReflectionEnumUnitCase. For a Backed Enum, they will all be instances of ReflectionEnumBackedCase.

Beispiele

Beispiel #1 ReflectionEnum::getCases() example

<?php
enum Suit
{
case
Hearts;
case
Diamonds;
case
Clubs;
case
Spades;
}

$rEnum = new ReflectionEnum(Suit::class);

$cases = $rEnum->getCases();

foreach (
$cases as $rCase) {
var_dump($rCase->getValue());
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

enum(Suit::Hearts)
enum(Suit::Diamonds)
enum(Suit::Clubs)
enum(Suit::Spades)

Siehe auch

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top