3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct(public public(set) readonly array $x = [1, 2, 3]) { } } $f = new Foo(); $f->x['x'] = 'y'; var_dump($f);
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Cannot indirectly modify readonly property Foo::$x in /in/vS0ij:8 Stack trace: #0 {main} thrown in /in/vS0ij on line 8
Process exited with code 255.
Output for 8.3.0 - 8.3.30
Fatal error: Multiple access type modifiers are not allowed in /in/vS0ij on line 4
Process exited with code 255.

preferences:
162.24 ms | 1087 KiB | 8 Q