在
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;
关于如何解决这个问题的任何想法?