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; } } $a = new Q(1, 2); $b = $a->cloneMutated(["bar" => 3]); var_dump($b); $c = $a->cloneMutated(["foo" => 4]); var_dump($c);
Output for git.master, git.master_jit, rfc.property-hooks
object(Q)#2 (2) { ["foo":"Q":private]=> int(1) ["bar":protected]=> int(3) } object(Q)#3 (2) { ["foo":"Q":private]=> int(4) ["bar":protected]=> int(2) }

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:
73 ms | 401 KiB | 8 Q