开发者

php: new object from "ClassName" and array of args

开发者 https://www.devze.com 2023-03-09 08:02 出处:网络
I have string c开发者_如何学Containing classname and an array of args. $classname($args) works, but in this case I have only 1 argument in constructor

I have string c开发者_如何学Containing classname and an array of args.

$classname($args) works, but in this case I have only 1 argument in constructor

Anyone know, how to do this with args expanded?


$reflection = new ReflectionClass($classname);
$object = $reflection->newInstanceArgs($args);

http://php.net/reflection


Haha I just asked this question: PHP passing a class as a reference?

And you can't expand the $args. You could try passing $args[0], $args[1] etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消