3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct(public readonly string $name) {} } class FancyArray { public function __construct(public readonly array $array = []) {} public function addElement(mixed $element): self { if (false === $element instanceof Foo) { throw new Exception("GOVNYAK!!!"); } return new self(array_merge($this->array, [$element])); } public function removeElementByIndex(mixed $index): self { return new self(array_splice(...[$this->array, $index, 1])); } } $array = new FancyArray([new Foo('a'), new Foo('b')]); $modifiedArray = $array->removeElementByIndex(1) ->addElement(new Foo('c')) ->addElement(new Foo('d')); var_dump($array); var_dump($modifiedArray);
Output for git.master_jit, git.master, rfc.property-hooks
object(FancyArray)#1 (1) { ["array"]=> array(2) { [0]=> object(Foo)#2 (1) { ["name"]=> string(1) "a" } [1]=> object(Foo)#3 (1) { ["name"]=> string(1) "b" } } } object(FancyArray)#7 (1) { ["array"]=> array(3) { [0]=> object(Foo)#3 (1) { ["name"]=> string(1) "b" } [1]=> object(Foo)#5 (1) { ["name"]=> string(1) "c" } [2]=> object(Foo)#4 (1) { ["name"]=> string(1) "d" } } }

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:
47.71 ms | 407 KiB | 5 Q