3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] class A {} class B {} #[A] function a(): void {} #[B] function b(): void {} $a = new ReflectionFunction('a'); $b = new ReflectionFunction('b'); foreach([$a, $b] as $reflection) { $attributes = $reflection->getAttributes(); foreach ($attributes as $attribute) { var_dump($attribute->getName()); var_dump($attribute->getArguments()); var_dump($attribute->newInstance()); } }
Output for 8.0.8, 8.1.23 - 8.1.33, 8.2.10 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.25, 8.4.1 - 8.4.12
string(1) "A" array(0) { } object(A)#4 (0) { } string(1) "B" array(0) { } Fatal error: Uncaught Error: Attempting to use non-attribute class "B" as attribute in /in/QGQRF:23 Stack trace: #0 /in/QGQRF(23): ReflectionAttribute->newInstance() #1 {main} thrown in /in/QGQRF on line 23
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(1) "A" array(0) { } object(A)#4 (0) { } string(1) "B" array(0) { } Fatal error: Uncaught Error: Attempting to use non-attribute class "B" as attribute in /in/QGQRF:23 Stack trace: #0 /in/QGQRF(23): ReflectionAttribute->newInstance() #1 {main} thrown in /in/QGQRF on line 23
Process exited with code 255.

preferences:
75.51 ms | 408 KiB | 5 Q