3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct( public readonly array $bar, ) {} } $ref = 42; $bar = [&$ref]; $foo = new Foo($bar); var_dump($foo); $ref = 43; var_dump($foo);
Output for 8.1.0 - 8.1.13
object(Foo)#1 (1) { ["bar"]=> array(1) { [0]=> &int(42) } } object(Foo)#1 (1) { ["bar"]=> array(1) { [0]=> &int(43) } }
Output for 8.0.1 - 8.0.26
Parse error: syntax error, unexpected token "array", expecting variable in /in/4PXG2e on line 5
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/4PXG2e on line 5
Process exited with code 255.

preferences:
204.25 ms | 1395 KiB | 78 Q