开发者

PHP: how to make new object of class with name stored in member string?

So I want to do something开发者_如何学C like this:

$ob = new $this->other_class_name;

but it fails. How can I do it without storing other_class_name in local variable?


Save the name in another variable:

$class = $this->other_class_name;
$ob = new $class;


Try this:

$class = get_class($this->other_class_name);
$ob = new $class;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜