3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class A implements IteratorAggregate { function __construct(public string $foo = 'bar') {} function getIterator() : Traversable { return new ArrayIterator($this); } } $obj = new A; foreach ($obj as $k => &$v) { $v = 'baz'; } var_dump($obj); // changed a readonly property
Output for 8.2.5 - 8.2.9
Fatal error: Uncaught Error: Cannot acquire reference to readonly property A::$foo in /in/12vrb:12 Stack trace: #0 {main} thrown in /in/12vrb on line 12
Process exited with code 255.
Output for 8.2.0 - 8.2.4
object(A)#1 (1) { ["foo"]=> &string(3) "baz" }
Output for 8.1.0 - 8.1.22
Parse error: syntax error, unexpected token "readonly", expecting end of file in /in/12vrb on line 3
Process exited with code 255.
Output for 8.0.1 - 8.0.30
Parse error: syntax error, unexpected token "class" in /in/12vrb on line 3
Process exited with code 255.

preferences:
194.58 ms | 1395 KiB | 69 Q