Why, in a class instance context, don't calls of the form $this->className::staticMethod
work, but calls of the form $className::staticMethod
do work?
In the example below callDoSomething2
works, but callDoSomething
does not work (I get a parser error). I'm using PHP version 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();