3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct( public string &$ref { get => $this->ref ?? 'null'; set => $this->ref = $value; } ) {} } $var = 'hello'; $foo = new Foo($var); $var = "world"; echo $foo->ref;
Output for 8.4.1 - 8.4.11
Fatal error: Uncaught Error: Indirect modification of Foo::$ref is not allowed in /in/JRArK:5 Stack trace: #0 /in/JRArK(10): Foo->__construct('hello') #1 {main} Next Error: Cannot assign by reference to overloaded object in /in/JRArK:5 Stack trace: #0 /in/JRArK(10): Foo->__construct('hello') #1 {main} thrown in /in/JRArK on line 5
Process exited with code 255.
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.24
Parse error: syntax error, unexpected token "{", expecting ")" in /in/JRArK on line 5
Process exited with code 255.

preferences:
156.4 ms | 1001 KiB | 7 Q