3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class Foo { public function __construct( public int $value, ) {} } $foo = new Foo(42); var_dump($foo); $ao = new ArrayObject($foo); $ao['value'] = 666; var_dump($foo);
Output for 8.5.0 - 8.5.3
object(Foo)#1 (1) { ["value"]=> int(42) } Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in /in/4Fbgr on line 13 object(Foo)#1 (1) { ["value"]=> int(666) }
Output for 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18
object(Foo)#1 (1) { ["value"]=> int(42) } object(Foo)#1 (1) { ["value"]=> int(666) }
Output for 8.1.34
Parse error: syntax error, unexpected token "readonly", expecting end of file in /in/4Fbgr on line 3
Process exited with code 255.

preferences:
39.04 ms | 848 KiB | 4 Q