Reflection ReflectionEnum::hasCase

(PHP 8 >= 8.1.0)

ReflectionEnum::hasCase — Checks for a case on an Enum


설명

public ReflectionEnum::hasCase(string $name): bool

주어진 케이스가 Enum에 정의되어 있는지 확인합니다.


매개변수

name
The case to check for.

반환 값

케이스가 정의되어 있으면 true, 그렇지 않으면 false입니다.


Examples

예제 #1 ReflectionEnum::hasCase() 예제

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

기타