クラスインスタンスのコンテキストで、フォームの呼び出しは機能しないのに、フォームの$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();