3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $foo =2; } class Hydrator { public function getPrivate($obj, $attribute) { $getter = function(){return $obj->$attribute;}; return \Closure::bind($getter, $obj); } } $hydrated = new Hydrator(); $obj = new Foo(); var_dump($obj->foo); $getter = $hydrated->getPrivate($obj, 'foo'); var_dump($getter());
based on Kraek
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Cannot access private property Foo::$foo in /in/WZW7D:17 Stack trace: #0 {main} thrown in /in/WZW7D on line 17
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Fatal error: Cannot access private property Foo::$foo in /in/WZW7D on line 17
Process exited with code 255.