PHP 可以将类名中的对象实例化为字符串吗? [英] Can PHP instantiate an object from the name of the class as a string?
本文介绍了PHP 可以将类名中的对象实例化为字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果类名存储在字符串中,PHP 是否可以从类名实例化对象?
Is it possible in PHP to instantiate an object from the name of a class, if the class name is stored in a string?
推荐答案
是的,当然.
$className = 'MyClass';
$object = new $className;
这篇关于PHP 可以将类名中的对象实例化为字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文