我试图弄清楚如何捕获 PHP 中对对象调用的任何方法。我知道魔术函数__call
,但它仅针对被调用对象上不存在的方法触发。
例如我有这样的事情:
class Foo
{
public function bar()
{
echo 'foobar';
}
public function override($method_name,$method_args)
{
echo 'Calling method ',$method_name,'<br />';
$this->$method_name($method_args); //dirty, but working
}
}
当我这样做时:
$foo = new Foo();
$foo->bar();
我想要这个输出:
Calling method bar
foobar
而不是这个:
foobar
有什么办法可以做到这一点?请帮忙 :)