3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Traitor { public function cloneMutated($settings) { $object = clone $this; foreach ($settings as $name => $val) { $object->$name = $val; } return $object; } } class Q { use Traitor; private $foo; protected $bar; public function __construct($foo, $bar) { $this->foo = $foo; $this->bar = $bar; } } class Z extends Q { private $asd; } $a = new Z(1, 2); $b = $a->cloneMutated(["bar" => 3]); var_dump($b); $c = $a->cloneMutated(["asd" => 4]); var_dump($c);
Output for git.master, git.master_jit, rfc.property-hooks
object(Z)#2 (3) { ["foo":"Q":private]=> int(1) ["bar":protected]=> int(3) ["asd":"Z":private]=> NULL } Fatal error: Uncaught Error: Cannot access private property Z::$asd in /in/jP1bu:8 Stack trace: #0 /in/jP1bu(33): Q->cloneMutated(Array) #1 {main} thrown in /in/jP1bu on line 8
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:
49.39 ms | 401 KiB | 8 Q