3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'baz'; private function taz() { return 'waz'; } } var_dump((new ReflectionProperty(Foo::class, 'bar'))->getValue(new Foo)); var_dump((new ReflectionMethod(Foo::class, 'taz'))->invoke(new Foo));
Output for 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
string(3) "baz" string(3) "waz"
Output for 8.0.1 - 8.0.30
Fatal error: Uncaught ReflectionException: Cannot access non-public property Foo::$bar in /in/PNeeZ:8 Stack trace: #0 /in/PNeeZ(8): ReflectionProperty->getValue(Object(Foo)) #1 {main} thrown in /in/PNeeZ on line 8
Process exited with code 255.

preferences:
70.16 ms | 407 KiB | 5 Q