3v4l.org

run code in 300+ 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
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:
95.76 ms | 407 KiB | 5 Q