【发布时间】:2010-06-12 03:16:02
【问题描述】:
我有一个名为 $theclass 的变量,它是一个字符串“Home_class”。如何从该字符串中定义一个类?我需要这样做的原因是变量会发生变化,我希望能够声明变量等于的类。
【问题讨论】:
我有一个名为 $theclass 的变量,它是一个字符串“Home_class”。如何从该字符串中定义一个类?我需要这样做的原因是变量会发生变化,我希望能够声明变量等于的类。
【问题讨论】:
使用new 关键字。
$theclass = 'My_class';
$x = new $theclass(); // $x is now an instance of My_class
【讨论】: