3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { private readonly array $fruits; public function __construct() { $this->fruits = ['banana', 'pear', 'apple']; \sort($this->fruits); } } new Foo();
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught Error: Cannot indirectly modify readonly property Foo::$fruits in /in/5POee:8 Stack trace: #0 /in/5POee(12): Foo->__construct() #1 {main} thrown in /in/5POee on line 8
Process exited with code 255.
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.5 - 8.3.30
Fatal error: Uncaught Error: Cannot modify readonly property Foo::$fruits in /in/5POee:8 Stack trace: #0 /in/5POee(12): Foo->__construct() #1 {main} thrown in /in/5POee on line 8
Process exited with code 255.
Output for 8.0.1 - 8.0.29
Parse error: syntax error, unexpected token "array", expecting variable in /in/5POee on line 4
Process exited with code 255.

preferences:
70.41 ms | 991 KiB | 4 Q