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 可以将类名中的对象实例化为字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!