php*_*utt 3 php static-methods instantiation php-5.2
我在调用类中的静态函数时遇到使用变量作为类名的问题.我的代码如下:
class test {
static function getInstance() {
return new test();
}
}
$className = "test";
$test = $className::getInstance();
Run Code Online (Sandbox Code Playgroud)
我必须将类名定义为变量,因为类的名称来自数据库,所以我永远不知道要创建实例的类.
注意:目前我收到以下错误:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
Run Code Online (Sandbox Code Playgroud)
谢谢