<?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']));
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.
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.