Php: new object from "ClassName" and an array of arguments

I have a string containing the class name and an array of arguments.
$ classname ($ args) works, but in this case I only have 1 argument in the constructor
Does anyone know how to do this with the args extension?

+3
source share
2 answers
$reflection = new ReflectionClass($classname);
$object = $reflection->newInstanceArgs($args);

http://php.net/reflection

+7
source

Haha, I just asked this question: PHP passed the class as a link?

And you cannot expand $args. You can try to skip $args[0], $args[1], etc.

-1
source

All Articles