1--TEST-- 2ReflectionEnum::getCases() 3--FILE-- 4<?php 5 6enum Enum_ { 7 case Foo; 8 const Bar = self::Foo; 9} 10 11enum IntEnum: int { 12 case Foo = 0; 13 const Bar = self::Foo; 14} 15 16function test(string $enumName, string $caseName) { 17 try { 18 $reflectionEnum = new ReflectionEnum($enumName); 19 var_dump($reflectionEnum->getCase($caseName)); 20 } catch (Throwable $e) { 21 echo get_class($e) . ': ' . $e->getMessage() . "\n"; 22 } 23} 24 25test(Enum_::class, 'Foo'); 26test(Enum_::class, 'Bar'); 27test(Enum_::class, 'Baz'); 28 29test(IntEnum::class, 'Foo'); 30test(IntEnum::class, 'Bar'); 31test(IntEnum::class, 'Baz'); 32 33?> 34--EXPECT-- 35object(ReflectionEnumUnitCase)#2 (2) { 36 ["name"]=> 37 string(3) "Foo" 38 ["class"]=> 39 string(5) "Enum_" 40} 41ReflectionException: Enum_::Bar is not a case 42ReflectionException: Case Enum_::Baz does not exist 43object(ReflectionEnumBackedCase)#2 (2) { 44 ["name"]=> 45 string(3) "Foo" 46 ["class"]=> 47 string(7) "IntEnum" 48} 49ReflectionException: IntEnum::Bar is not a case 50ReflectionException: Case IntEnum::Baz does not exist 51