3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { public function __construct( private readonly int $a, private readonly string $b, ) { } public function withA(int $a): self { return new self(...(get_defined_vars() + get_object_vars($this))); } public function withB(string $b): self { return new self(...(get_defined_vars() + get_object_vars($this))); } } $f = (new Foo(1, "foo")) ->withA(2) ->withB("bar"); var_dump($f);
Output for git.master, rfc.property-hooks, git.master_jit
object(Foo)#1 (2) { ["a":"Foo":private]=> int(2) ["b":"Foo":private]=> string(3) "bar" }

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:
48.25 ms | 2679 KiB | 4 Q