在PHP中,你可以从(其中包含在一个阵列)这样一个对象实例调用类的静态方法:
$myArray['instanceOfMyClass']::staticMethod(); // works
但由于某些原因,当我使用$this
变量,我得到一个解析错误。 例如:
$this->myArray['instanceOfMyClass']::staticMethod(); // PARSING ERROR
只是为了说明我的意思:
class MyClass{
public static function staticMethod(){ echo "staticMethod called\n"; }
}
$myArray = array();
$myArray['instanceOfMyClass'] = new MyClass;
$myArray['instanceOfMyClass']::staticMethod(); // works
class RunCode
{
private $myArray;
public function __construct(){
$this->myArray = array();
$this->myArray['instanceOfMyClass'] = new MyClass;
$this->myArray['instanceOfMyClass']::staticMethod(); // PARSING ERROR
}
}
new RunCode;
如何解决这个问题的任何想法?