【发布时间】:2018-08-01 15:15:59
【问题描述】:
我在 PHP 中使用重载,我的 PHP 代码有什么问题,即使它只有 8 行代码:
class c1{
public function __call($name,$array){
if($this->$name()){ return true;}
}
}
$cl = new c1;
echo $cl->m1();
它说:
“致命错误:允许的内存大小为 134217728 字节已用尽(尝试分配 262144 字节)”
【问题讨论】:
-
您尝试调用
m1(),调用__call()并尝试调用m1()调用__call()并尝试调用m1()等... 无限循环。至少没完没了,直到内存耗尽。 -
你可能想要
if(method_exists($this, $name)){ return true;}