3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @template T */ final class ReadonlyReference { /** * @param T $value */ public function __construct( public readonly mixed $value ) {} } /** * @template T */ final class Reference { /** * @param T $value */ public function __construct( public mixed $value ) {} } /** * @param ReadonlyReference<list<int>> $foo */ function foo(ReadonlyReference $foo): void { foreach($foo->value as $s) { var_dump($s); } $foo->value[] = 1; } $ref = new ReadonlyReference([ 1, 2, 3 ]); foo($ref);
Output for git.master, git.master_jit
int(1) int(2) int(3) Fatal error: Uncaught Error: Cannot modify readonly property ReadonlyReference::$value in /in/ehYQh:35 Stack trace: #0 /in/ehYQh(42): foo(Object(ReadonlyReference)) #1 {main} thrown in /in/ehYQh on line 35
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.17 ms | 939 KiB | 4 Q