3v4l.org

run code in 300+ PHP versions simultaneously
<?php class My extends ReflectionMethod { public $name = 'test'; public $className; } $ref = new My(My::class, 'getDeclaringClass'); $ref->className = new stdClass; echo $ref->name, get_class($ref->class);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Type of My::$name must be string (as in class ReflectionFunctionAbstract) in /in/huWb7 on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.30
getDeclaringClass Fatal error: Uncaught TypeError: get_class(): Argument #1 ($object) must be of type object, string given in /in/huWb7:13 Stack trace: #0 {main} thrown in /in/huWb7 on line 13
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
getDeclaringClass Warning: get_class() expects parameter 1 to be object, string given in /in/huWb7 on line 13

preferences:
239.42 ms | 403 KiB | 330 Q