3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &readPrivate($object, $k, $context = null) { if (null === $context) { $context = $object; } $closure = function & () use ($k) { return $this->$k; }; $binding = Closure::bind( $closure, $object, $context); $value = & $binding->__invoke(); return $value; } class B { private $xb = 'xb_b'; private $x = 'xb'; public $z = 'zb'; } class C extends B { private $x = 'xc'; private $y = 'yc'; public $z = 'zc'; } $c = new C; var_dump(readPrivate($c, 'x')); var_dump(readPrivate($c, 'x', B::class)); var_dump(readPrivate($c, 'x', ReflectionClass::class));
Output for git.master, git.master_jit, rfc.property-hooks
string(2) "xc" string(2) "xb" Warning: Cannot bind closure to scope of internal class ReflectionClass in /in/2BZRg on line 13 Fatal error: Uncaught Error: Call to a member function __invoke() on null in /in/2BZRg:18 Stack trace: #0 /in/2BZRg(41): readPrivate(Object(C), 'x', 'ReflectionClass') #1 {main} thrown in /in/2BZRg on line 18
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
168.56 ms | 406 KiB | 5 Q