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