开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜