3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { readonly int $foo; public function __set($key, $value) { echo "__set called with {$value}\n"; } } $f = new Foo; $f->foo = 43;
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Cannot modify protected(set) readonly property Foo::$foo from global scope in /in/ld621:12 Stack trace: #0 {main} thrown in /in/ld621 on line 12
Process exited with code 255.
Output for 8.1.13 - 8.1.34, 8.2.21 - 8.2.30, 8.3.5 - 8.3.30
Fatal error: Uncaught Error: Cannot initialize readonly property Foo::$foo from global scope in /in/ld621:12 Stack trace: #0 {main} thrown in /in/ld621 on line 12
Process exited with code 255.

preferences:
51.27 ms | 744 KiB | 4 Q