3v4l.org

run code in 500+ PHP versions simultaneously
<?php class ComplicatedConstructor { public function __construct( public readonly int $integer, public readonly float $float, public readonly bool $boolean, public readonly string $string, private ?\Closure $closure = null, public readonly float|string|null $optional = 'optional', ) {} } $outOfOrderArray = [ 'optional' => 'The optional', 'string' => 'The string', 'float' => (float) '42.5', 'integer' => 9001, 'boolean' => !true, ]; var_dump(new ComplicatedConstructor(...$outOfOrderArray));
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.2 - 8.3.31, 8.4.6, 8.5.3 - 8.5.6
object(ComplicatedConstructor)#1 (6) { ["integer"]=> int(9001) ["float"]=> float(42.5) ["boolean"]=> bool(false) ["string"]=> string(10) "The string" ["closure":"ComplicatedConstructor":private]=> NULL ["optional"]=> string(12) "The optional" }
Output for 8.0.30
Parse error: syntax error, unexpected identifier "int", expecting variable in /in/lfWrQ on line 6
Process exited with code 255.
Output for 7.4.2
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/lfWrQ on line 6
Process exited with code 255.

preferences:
54.9 ms | 524 KiB | 4 Q