3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { private $privateProperty = '7Learn.com'; } $obj = new Foo; $reflector = new ReflectionClass($obj); $property = $reflector->getProperty('privateProperty'); //$property->setAccessible(true); var_dump($property->getValue($obj));
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(10) "7Learn.com"
Output for 8.0.1 - 8.0.30
Fatal error: Uncaught ReflectionException: Cannot access non-public property Foo::$privateProperty in /in/dWVYo:14 Stack trace: #0 /in/dWVYo(14): ReflectionProperty->getValue(Object(Foo)) #1 {main} thrown in /in/dWVYo on line 14
Process exited with code 255.

preferences:
66.44 ms | 1107 KiB | 4 Q