3v4l.org

run code in 300+ PHP versions simultaneously
<?php function &readPrivate($object, $k, $context = null) { $closure = function & () use ($k) { return $this->$k; }; $binding = Closure::bind( $closure, $object, $context); $value = & $binding->__invoke(); return $value; } class B { private $x = 'xb'; public $z = 'zb'; } class C { private $x = 'xc'; private $y = 'yc'; public $z = 'zc'; } $c = new C; var_dump(readPrivate($c, 'x', $c)); # var_dump(readPrivate($c, 'x', B::class));
Output for git.master, git.master_jit, rfc.property-hooks
string(2) "xc"

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.96 ms | 405 KiB | 5 Q