为什么在类实例上下文中不要调用表格$this->className::staticMethod
的工作,但$className::staticMethod
表格的调用确实可行?如何调用存储为变量的类的静态方法?
在下面的例子callDoSomething2
工程,但callDoSomething
不起作用(我得到一个解析器错误)。我使用PHP 5.3.15版本。
<?php
class A {
private $className;
public function __construct($className) {
$this->className = $className;
}
public function callDoSomething() {
$this->className::doSomething();
}
public function callDoSomething2() {
$className = $this->className;
$className::doSomething();
}
}
class B {
public static function doSomething() {
echo "hello\n";
}
}
$a = new A('B');
$a->doSomething();
重复的线路使用的东西:http://stackoverflow.com/questions/2108795/dynamic-static- method-call-in-php – 2013-02-13 22:51:20
请参阅http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php – 2013-02-13 22:58:51