3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function object_builder($params) { $klass = array_shift($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.17, 8.3.0 - 8.3.4
Deprecated: Creation of dynamic property A::$a is deprecated in /in/BuLC7 on line 12 Fatal error: Uncaught TypeError: A::__construct(): Argument #1 ($a) must be of type int, string given, called in /in/BuLC7 on line 7 and defined in /in/BuLC7:11 Stack trace: #0 /in/BuLC7(7): A->__construct('a') #1 /in/BuLC7(16): object_builder(Array) #2 {main} thrown in /in/BuLC7 on line 11
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
Fatal error: Uncaught TypeError: A::__construct(): Argument #1 ($a) must be of type int, string given, called in /in/BuLC7 on line 7 and defined in /in/BuLC7:11 Stack trace: #0 /in/BuLC7(7): A->__construct('a') #1 /in/BuLC7(16): object_builder(Array) #2 {main} thrown in /in/BuLC7 on line 11
Process exited with code 255.
Output for 7.3.16 - 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/BuLC7 on line 7 and defined in /in/BuLC7:11 Stack trace: #0 /in/BuLC7(7): A->__construct('a') #1 /in/BuLC7(16): object_builder(Array) #2 {main} thrown in /in/BuLC7 on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 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/BuLC7 on line 7 and defined in /in/BuLC7:11 Stack trace: #0 /in/BuLC7(7): A->__construct('a') #1 /in/BuLC7(16): object_builder(Array) #2 {main} thrown in /in/BuLC7 on line 11
Process exited with code 255.

preferences:
159.22 ms | 402 KiB | 169 Q