3v4l.org

run code in 300+ PHP versions simultaneously
<?php // lint >= 8.1 namespace ReadonlyPropertyPassedByRef; class Foo { public readonly int $bar; public function set(int &$i) { $this->bar = &$i; } } $i = 1; $foo = new Foo(); $foo->set($i); $i = 20; var_dump($foo->bar);
Output for 8.1.0 - 8.1.1
int(20)
Output for 8.0.1 - 8.0.14
Parse error: syntax error, unexpected identifier "int", expecting variable in /in/f19r1 on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.27
Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in /in/f19r1 on line 8
Process exited with code 255.

preferences:
144.65 ms | 1399 KiB | 49 Q