当我尝试这个:
<?php
class myParent {
public function __call($method, $params) {
echo "from __call";
}
public function __callStatic($method, $params) {
echo "from __callStatic";
}
}
class mySon extends myParent {
public function bar() {
myParent::foo();
}
}
(new mySon())->bar();
我期望得到这个输出:
from __callStatic
...,但实际上输出为:from __call
。有人能解释一下原因吗?
编辑:确切地说,我想知道如果我删除
__call
函数,那么它会触发__callStatic
,是否有办法在声明__call
时触发__callStatic
。
extends myParent
- 你将得到你需要的结果,因为类之间不再有关联。 - u_mulder