
ReflectionEnum::hasCase 메서드는 열거형의 특정 케이스를 검사할 때 사용됩니다.
예를 들어, 다음과 같은 열거형이 있다고 가정해 보겠습니다.
#hostingforum.kr
php
enum Color: string {
case RED = 'red';
case GREEN = 'green';
case BLUE = 'blue';
}
이 경우, Color::RED를 검사하는 방법은 다음과 같습니다.
#hostingforum.kr
php
if (Color::hasCase(Color::RED)) {
// Color::RED가 열거형에 존재하는 경우
}
hasCase 메서드의 반환 타입은 Bool입니다. 따라서 True/False를 반환합니다.
#hostingforum.kr
php
var_dump(Color::hasCase(Color::RED)); // bool(true)
var_dump(Color::hasCase(Color::YELLOW)); // bool(false)
2025-03-24 11:13