3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function object_builder($klass, $params) { return new $klass(...$params); } class A { public function __construct(int $a){ $this->a = $a; } } var_dump(object_builder('A', [0]), object_builder('A', ['a']));
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Deprecated: Creation of dynamic property A::$a is deprecated in /in/nVVpW on line 11 Fatal error: Uncaught TypeError: A::__construct(): Argument #1 ($a) must be of type int, string given, called in /in/nVVpW on line 6 and defined in /in/nVVpW:10 Stack trace: #0 /in/nVVpW(6): A->__construct('a') #1 /in/nVVpW(15): object_builder('A', Array) #2 {main} thrown in /in/nVVpW on line 10
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: A::__construct(): Argument #1 ($a) must be of type int, string given, called in /in/nVVpW on line 6 and defined in /in/nVVpW:10 Stack trace: #0 /in/nVVpW(6): A->__construct('a') #1 /in/nVVpW(15): object_builder('A', Array) #2 {main} thrown in /in/nVVpW on line 10
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to A::__construct() must be of the type int, string given, called in /in/nVVpW on line 6 and defined in /in/nVVpW:10 Stack trace: #0 /in/nVVpW(6): A->__construct('a') #1 /in/nVVpW(15): object_builder('A', Array) #2 {main} thrown in /in/nVVpW on line 10
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
Fatal error: Uncaught TypeError: Argument 1 passed to A::__construct() must be of the type integer, string given, called in /in/nVVpW on line 6 and defined in /in/nVVpW:10 Stack trace: #0 /in/nVVpW(6): A->__construct('a') #1 /in/nVVpW(15): object_builder('A', Array) #2 {main} thrown in /in/nVVpW on line 10
Process exited with code 255.

preferences:
301.13 ms | 402 KiB | 203 Q