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.4.1 - 8.4.12
/** * Class comment */ Class [ <user> class SomeClass ] { @@ /in/U1vT0 10-26 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] { /** * Property comment */ 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 comment */ Property [ private string $someProperty ] Attribute [ SomeAttr ]
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25
/** * 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:
149.93 ms | 414 KiB | 5 Q