(PHP 8 >= 8.1.0)
ReflectionEnum::hasCase — Checks for a case on an Enum
Determines if a given case is defined on an Enum.
name
The case to check for.
Приклад #1 ReflectionEnum::hasCase() example
<?php
enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}
$rEnum = new ReflectionEnum(Suit::class);
var_dump($rEnum->hasCase('Hearts'));
var_dump($rEnum->hasCase('Horseshoes'));
?>
Поданий вище приклад виведе:
bool(true) bool(false)