3v4l.org

run code in 300+ PHP versions simultaneously
<?php #[Attribute] class SomeAttr {} /** * Class comment */ #[SomeAttr] class SomeClass { /** * Property comment */ #[SomeAttr] private string $someProperty; /** * Method comment */ #[SomeAttr] public function someMethod(string $someParam): void { } } $reflection = new ReflectionClass(SomeClass::class); echo (string) $reflection; echo (string) $reflection->getMethod('someMethod'); echo (string) $reflection->getProperty('someProperty'); echo $reflection->getMethod('someMethod')->getAttributes()[0];
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
/** * Class comment */ Class [ <user> class SomeClass ] { @@ /in/U1vT0 10-26 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ private string $someProperty ] } - Methods [1] { /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Property [ private string $someProperty ] Attribute [ SomeAttr ]
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 /** * Class comment */ Class [ <user> class SomeClass ] { @@ /in/U1vT0 10-26 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ private string $someProperty ] } - Methods [1] { /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Property [ private string $someProperty ] Attribute [ SomeAttr ]
Output for 8.0.0 - 8.0.30
/** * Class comment */ Class [ <user> class SomeClass ] { @@ /in/U1vT0 10-26 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ private string $someProperty ] } - Methods [1] { /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Property [ private string $someProperty ] Fatal error: Uncaught Error: Object of class ReflectionAttribute could not be converted to string in /in/U1vT0:34 Stack trace: #0 {main} thrown in /in/U1vT0 on line 34
Process exited with code 255.
Output for 7.4.0 - 7.4.33
/** * Class comment */ Class [ <user> class SomeClass ] { @@ /in/U1vT0 10-26 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { Property [ <default> private $someProperty ] } - Methods [1] { /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } } } /** * Method comment */ Method [ <user> public method someMethod ] { @@ /in/U1vT0 22 - 25 - Parameters [1] { Parameter #0 [ <required> string $someParam ] } - Return [ void ] } Property [ <default> private $someProperty ] Fatal error: Uncaught Error: Call to undefined method ReflectionMethod::getAttributes() in /in/U1vT0:34 Stack trace: #0 {main} thrown in /in/U1vT0 on line 34
Process exited with code 255.
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/U1vT0 on line 16
Process exited with code 255.

preferences:
175.55 ms | 401 KiB | 150 Q