Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
据我所知,new $className();5.3 肯定支持使用变量进行类实例化,但是我不确定 5.2 版本,我无法检查这在 5.2 上是否可以正常工作。
new $className();
谁能告诉我支持哪些版本?
在 5.2.4-2 中测试,运行良好:)
编辑 - -
在 PHP 5.2 中你做不到$className::method(),你得到了著名的
$className::method()
unexpected T_PAAMAYIM_NEKUDOTAYIM
但你可以new $className();
这不是特定于 PHP5。它也适用于 PHP4。
见http://php.net/manual/en/keyword.class.php#99638
手册说在 5.3.0 中引入
http://us3.php.net/manual/en/language.oop5.basic.php