【发布时间】:2013-02-13 22:47:06
【问题描述】:
为什么在类实例上下文中,$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();
【问题讨论】:
标签: php