PHP 8.4.1 Released!

ReflectionEnum::getCase

(PHP 8 >= 8.1.0)

ReflectionEnum::getCaseReturns a specific case of an Enum

Опис

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

Параметри

name

The name of the case to retrieve.

Значення, що повертаються

An instance of ReflectionEnumUnitCase or ReflectionEnumBackedCase, as appropriate.

Приклади

Приклад #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());
?>

Поданий вище приклад виведе:

enum(Suit::Clubs)

Прогляньте також

add a note

User Contributed Notes

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