File tree Expand file tree Collapse file tree 1 file changed +17
-17
lines changed Expand file tree Collapse file tree 1 file changed +17
-17
lines changed Original file line number Diff line number Diff line change 11--TEST--
2- Reflection shows user-defined BackedEnum:: values() when present
2+ BackedEnum: reflection shows whether values() is native or user-defined
33--FILE--
44<?php
55
6- enum E: int {
7- case A = 1 ;
6+ // Native implementation
7+ enum NativeEnum: string {
8+ case A = 'a ' ;
9+ }
10+
11+ // User-defined implementation
12+ enum UserEnum: string {
13+ case B = 'b ' ;
814
915 public static function values (): array {
10- return [ ' custom ' ] ;
16+ return array_map ( fn ( $ c ) => $ c -> value , self :: cases ()) ;
1117 }
1218}
1319
14- $ m = new ReflectionMethod (E::class, 'values ' );
15- var_dump ($ m ->isStatic ());
16- var_dump ($ m ->isPublic ());
17- var_dump ($ m ->isInternal ());
18- echo $ m ->getDeclaringClass ()->getName (), "\n" ;
19- $ proto = $ m ->getPrototype ();
20- echo $ proto ->getDeclaringClass ()->getName (), "\n" ;
20+ $ nativeMethod = new ReflectionMethod (NativeEnum::class, 'values ' );
21+ $ userMethod = new ReflectionMethod (UserEnum::class, 'values ' );
22+
23+ echo "Native is internal: " . ($ nativeMethod ->isInternal () ? 'yes ' : 'no ' ) . "\n" ;
24+ echo "User is internal: " . ($ userMethod ->isInternal () ? 'yes ' : 'no ' ) . "\n" ;
2125
2226?>
2327--EXPECT--
24- bool(true)
25- bool(true)
26- bool(false)
27- E
28- BackedEnum
29-
28+ Native is internal: yes
29+ User is internal: no
You can’t perform that action at this time.
0 commit comments