3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $bar = 'baz'; } $foo = new Foo(); $reader = function & ($object, $property) { $value = & Closure::bind(function & () use ($property) { return $this->$property; }, $object, $object)->__invoke(); return $value; }; $bar = & $reader($foo, 'bar'); var_dump($bar); $bar = 'tab1'; var_dump($foo); echo $foo->bar;
based on HPiIq
Output for 7.0.0 - 7.2.0
string(3) "baz" object(Foo)#1 (1) { ["bar":"Foo":private]=> &string(4) "tab1" } Fatal error: Uncaught Error: Cannot access private property Foo::$bar in /in/VfieV:23 Stack trace: #0 {main} thrown in /in/VfieV on line 23
Process exited with code 255.
Output for 5.4.12 - 5.6.28
string(3) "baz" object(Foo)#1 (1) { ["bar":"Foo":private]=> &string(4) "tab1" } Fatal error: Cannot access private property Foo::$bar in /in/VfieV on line 23
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Fatal error: Call to undefined method Closure::bind() in /in/VfieV on line 10
Process exited with code 255.