3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_PROPERTY)] enum Types { case Int32; case Int64; case Float32; } define('Float32', Types::Float32); define('Int64', Types::Int64); define('Int32', Types::Int32); class Test { #[Int32] #[Blah] public int $value; } $t = new Test(); $r = new ReflectionClass($t); $attr = $r->getProperty('value')->getAttributes(); foreach($attr as &$a) { if (class_exists($a->getName())) { $a = $a->newInstance(); } else if(defined($a->getName())) { $a = constant($a->getName()); } } var_dump($attr);
Output for 8.5.0
Fatal error: Cannot apply #[\Attribute] to enum Types in /in/Vcl37 on line 4 Stack trace: #0 {main}
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.4.1 - 8.4.14
array(2) { [0]=> enum(Types::Int32) [1]=> &object(ReflectionAttribute)#8 (1) { ["name"]=> string(4) "Blah" } }
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28
array(2) { [0]=> enum(Types::Int32) [1]=> &object(ReflectionAttribute)#8 (0) { } }

preferences:
63.91 ms | 410 KiB | 5 Q