3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract readonly class A{ protected string $foo; public function __construct() { $this->foo = ''; } } readonly class B extends A { public function __construct() { $this->foo = 'foo'; } } $b = new B(); var_dump($b);
Output for 8.4.4 - 8.4.22, 8.5.0 - 8.5.7
object(B)#1 (1) { ["foo":protected]=> string(3) "foo" }
Output for 8.2.28 - 8.2.30, 8.3.5 - 8.3.30
Fatal error: Uncaught Error: Cannot initialize readonly property A::$foo from scope B in /in/PDmd0:13 Stack trace: #0 /in/PDmd0(17): B->__construct() #1 {main} thrown in /in/PDmd0 on line 13
Process exited with code 255.
Output for 8.1.34
Parse error: syntax error, unexpected token "readonly", expecting "abstract" or "final" or "class" in /in/PDmd0 on line 3
Process exited with code 255.

preferences:
55.65 ms | 664 KiB | 4 Q