3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] enum DemoEnum {} #[Attribute] trait DemoTrait {} #[Attribute] abstract class DemoAbstract {} #[Attribute] interface DemoInterface {} #[DemoEnum] #[DemoTrait] #[DemoAbstract] #[DemoInterface] function usesWrongAttrib() {} $r = new ReflectionFunction( 'usesWrongAttrib' ); $a = $r->getAttributes(); var_dump( $a ); foreach ( $a as $attrib ) { try { $attrib->newInstance(); } catch ( Error $e ) { echo get_class( $e ) . ": " . $e->getMessage() . "\n"; } }
Output for 8.5.0
Fatal error: Cannot apply #[\Attribute] to enum DemoEnum in /in/99PhY 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(4) { [0]=> object(ReflectionAttribute)#2 (1) { ["name"]=> string(8) "DemoEnum" } [1]=> object(ReflectionAttribute)#3 (1) { ["name"]=> string(9) "DemoTrait" } [2]=> object(ReflectionAttribute)#4 (1) { ["name"]=> string(12) "DemoAbstract" } [3]=> object(ReflectionAttribute)#5 (1) { ["name"]=> string(13) "DemoInterface" } } Error: Cannot instantiate enum DemoEnum Error: Cannot instantiate trait DemoTrait Error: Cannot instantiate abstract class DemoAbstract Error: Cannot instantiate interface DemoInterface
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28
array(4) { [0]=> object(ReflectionAttribute)#2 (0) { } [1]=> object(ReflectionAttribute)#3 (0) { } [2]=> object(ReflectionAttribute)#4 (0) { } [3]=> object(ReflectionAttribute)#5 (0) { } } Error: Cannot instantiate enum DemoEnum Error: Cannot instantiate trait DemoTrait Error: Cannot instantiate abstract class DemoAbstract Error: Cannot instantiate interface DemoInterface

preferences:
57.38 ms | 412 KiB | 5 Q