3v4l.org

run code in 300+ PHP versions simultaneously
<?php final readonly class A { public string $foo; public function __construct(string $foo) { $this->foo = $foo; } public function withFoo(string $foo): static { $other = clone $this; $other->foo = $foo; return $other; } } $a = new A('y')->withFoo('x')->withFoo('z'); var_dump($a);
Output for git.master_jit, git.master
Fatal error: Uncaught Error: Cannot modify readonly property A::$foo in /in/hnABl:12 Stack trace: #0 /in/hnABl(17): A->withFoo('x') #1 {main} thrown in /in/hnABl on line 12
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:
147.09 ms | 1314 KiB | 6 Q