3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class Foo { public function __construct( public bool $bool, public int $int, ) {} } $args = ['bar', '10']; $reflection = new \ReflectionClass(Foo::class); $constructor = $reflection->getConstructor(); $instance = $reflection->newInstance(...$args); var_dump($instance); // Expected new Foo(...$args);
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/KtY24 on line 7
Process exited with code 255.
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26
object(Foo)#3 (2) { ["bool"]=> bool(true) ["int"]=> int(10) } Fatal error: Uncaught TypeError: Foo::__construct(): Argument #1 ($bool) must be of type bool, string given, called in /in/KtY24 on line 21 and defined in /in/KtY24:6 Stack trace: #0 /in/KtY24(21): Foo->__construct('bar', '10') #1 {main} thrown in /in/KtY24 on line 6
Process exited with code 255.
Output for 8.5.0 - 8.5.11
object(Foo)#3 (2) { ["bool"]=> bool(true) ["int"]=> int(10) } Fatal error: Uncaught TypeError: Foo::__construct(): Argument #1 ($bool) must be of type bool, string given, called in /in/KtY24 on line 21 and defined in /in/KtY24:7 Stack trace: #0 /in/KtY24(21): Foo->__construct('bar', '10') #1 {main} thrown in /in/KtY24 on line 7
Process exited with code 255.

preferences:
41.84 ms | 1144 KiB | 11 Q