No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

ReflectionEnum::getCases

(PHP 8 >= 8.1.0)

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

Description

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).

PHP: ReflectionEnum::getCases - Manual Home of Manuel PHP  Contents Haut

Parameters

This function has no parameters.

PHP: ReflectionEnum::getCases - Manual Home of Manuel PHP  Contents Haut

Return Values

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.

PHP: ReflectionEnum::getCases - Manual Home of Manuel PHP  Contents Haut

Examples

Example #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());
}
?>

The above example will output:

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

PHP: ReflectionEnum::getCases - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function
Error Infobrol

Can not display this page of the Infobrol website

Type of error (18-01)

Unknown format specifier "&"

Please try again in a few minutes…

Return to the home page




Steph