如果我在 PHP 类中重载 __call
方法,如果我的代码不执行其他操作,我该如何调用实际方法?例如:
public function __call($name, $arguments)
{
if($name == 'tom')
{
$this->doName($name);
}
else
{
// Something here to carry on the __call maybe:
// $this->$name($arguments);
}
}
问题是 $arguments
是作为数组传递的,我怎么能继续通过 info $this->$name($arg, $arg, $ arg ...)
有正确的方法吗?
最佳答案
你可以调用:
return parent::__call($name, $arguments);
还是我误解了你的意思?
编辑:
如果你的意思是你想调用 $this->$name()
来尝试触发 parent::__call()
,那是行不通的。您将陷入无限循环,直到堆栈溢出和 php 崩溃(换句话说,这很糟糕)...
关于PHP 如何调用 parent::__call() 并传入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3462481/