3v4l.org

run code in 300+ PHP versions simultaneously
<?php // lint >= 8.1 namespace ReadonlyPropertyPassedByRef; class Foo { public readonly int $bar; public function __construct(int &$i) { $this->bar = &$i; } } $i = 1; $foo = new Foo($i); var_dump($foo->bar); $i = 2; var_dump($foo->bar);
Output for 8.1.0 - 8.1.1
int(1) int(2)
Output for 8.0.1 - 8.0.14
Parse error: syntax error, unexpected identifier "int", expecting variable in /in/RHZJm 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/RHZJm on line 8
Process exited with code 255.

preferences:
148.27 ms | 1403 KiB | 50 Q