3v4l.org

run code in 500+ PHP versions simultaneously
<?php class x { function __construct(protected readonly int $x) { } } class y extends x { function __construct(protected readonly int $x) { parent::__construct($x); } } new y(1); // Fatal error: Uncaught Error: Cannot modify readonly property y::$x class z extends x { function __construct(int $x) { parent::__construct($x); } } new z(1); // OK ?>
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.6
Fatal error: Uncaught Error: Cannot modify readonly property y::$x in /in/RIZ8k:4 Stack trace: #0 /in/RIZ8k(10): x->__construct(1) #1 /in/RIZ8k(14): y->__construct(1) #2 {main} thrown in /in/RIZ8k on line 4
Process exited with code 255.

preferences:
54.41 ms | 865 KiB | 4 Q