3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute(Attribute::TARGET_METHOD)] class SomeMethodAttribute {} #[SomeMethodAttribute] class XXX { } $reflection = (new ReflectionClass(XXX::class)); var_dump( $reflection->getAttributes()[0]->newInstance() ); ?>
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Attribute "SomeMethodAttribute" cannot target class (allowed targets: method) in /in/8lcoG:13 Stack trace: #0 /in/8lcoG(13): ReflectionAttribute->newInstance() #1 {main} thrown in /in/8lcoG on line 13
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Call to undefined method ReflectionClass::getAttributes() in /in/8lcoG:13 Stack trace: #0 {main} thrown in /in/8lcoG on line 13
Process exited with code 255.

preferences:
138.83 ms | 401 KiB | 121 Q