3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] class SomeAttr {} #[SomeAttr] class SomeClass { /** * Some comment */ #[SomeAttr] public function someMethod(string $someParam): void { } } $reflection = new ReflectionClass(SomeClass::class); echo (string) $reflection; echo (string) $reflection->getMethod('someMethod'); echo $reflection->getMethod('someMethod')->getAttributes()[0];
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Class [ <user> class SomeClass ] { @@ /in/Ht9pi 7-16 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [1] { /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Attribute [ SomeAttr ]
Output for 8.0.0 - 8.0.30
Class [ <user> class SomeClass ] { @@ /in/Ht9pi 7-16 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [1] { /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Fatal error: Uncaught Error: Object of class ReflectionAttribute could not be converted to string in /in/Ht9pi:23 Stack trace: #0 {main} thrown in /in/Ht9pi on line 23
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Class [ <user> class SomeClass ] { @@ /in/Ht9pi 7-16 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [1] { /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Some comment */ Method [ <user> public method someMethod ] { @@ /in/Ht9pi 12 - 15 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Fatal error: Uncaught Error: Call to undefined method ReflectionMethod::getAttributes() in /in/Ht9pi:23 Stack trace: #0 {main} thrown in /in/Ht9pi on line 23
Process exited with code 255.

preferences:
142.03 ms | 411 KiB | 5 Q