-1

可能重复:
PHP __call vs method_exists

我在__call()类中使用而不是方法。有什么方法可以影响这个类中 method_exists() 的结果吗?

4

1 回答 1

0

不,你不能。

__call 只是类上函数调用的“占位符”。

考虑一下:

Class MyClass
{
  private function Bar()
  {
     return 'Bar';
  }

  public function __call($name, $arguments)
  {
    return $this->Bar();
  }
}

$myClass = new MyClass();
echo $myClass->Foo( 'Foo' );

此代码将输出 'Bar' 方法 'Foo' 不存在,并通过调用 $MyClass->Foo('Foo') __call 启动。

显然,method_exists 无法知道 __call 将处理什么。

于 2012-09-11T13:37:01.177 回答