3v4l.org

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