【发布时间】:2013-03-01 10:54:01
【问题描述】:
请帮助我。 例如,我有一个类 Foo,它从类 Bar 扩展而来。
class Bar
{
public function __call($func, $args){
echo "Calling method {$func}";
}
public function __callstatic($func, $args){
echo "Calling static method {$func}";
}
public function run(){
echo "calling Bar::run method \n";
}
}
class Foo extends Bar
{
public $objBar;
public function __construct(){
$this -> objBar = new Bar();
}
public function callViaObject(){
$this -> objBar -> run();
$this -> objBar -> run1();
}
public function callViaParent(){
parent::run();
parent::run1();
}
}
$foo = new foo();
$foo -> callViaObject();
/* output
calling Bar::run method \n
Calling method run1; */
$foo -> callViaParent();
/* output
calling Bar::run method \n
Calling method run1; !! */
这里有个问题,当我从子类调用parent::的方法,而父类有对象时,调用方法parent::不是静态调用。
那么我如何签入Bar 类,如何调用方法?
我可以检查调用类型是 parent:: 吗?
非常感谢大家!!
【问题讨论】:
-
您是否尝试过将
__callstatic更改为__callStatic(注意大写S)?这可能是原因。 -
我试过了,还是一样。