“全球”;方法“U缺失”;在PHP中?

“全球”;方法“U缺失”;在PHP中?,php,oop,method-missing,Php,Oop,Method Missing,可能重复: 我可以实现_call(),以提供PHP类中缺少方法的行为。有没有办法在全局范围内提供相同的功能 我想要这样的东西: function __call( $name, $arguments ) { echo( sprintf( '%s called', $name ) ); } echo( 'before' ); call_undefined_function( $a, $b ); echo( 'after' ); 产出: before call_undefined_funct

可能重复:

我可以实现_call(),以提供PHP类中缺少方法的行为。有没有办法在全局范围内提供相同的功能

我想要这样的东西:

function __call( $name, $arguments ) {
  echo( sprintf( '%s called', $name ) );
}

echo( 'before' );
call_undefined_function( $a, $b );
echo( 'after' );
产出:

before
call_undefined_function called
after

您可以编写自己的,并在其中使用
函数\u exists()
生成所需的消息。只要不在错误处理程序中停止脚本,执行就会继续。

别担心,我找到它只是因为我回答了它……我认为这不会处理未定义的函数错误。我尝试了
php-r“set_error_handler('var_dump');d()”
这将失败(错误处理程序不会被调用,致命的错误消息),而
php-r“set_error_handler('var_dump');echo$undefar;”
按预期工作。@aularon,我没有尝试过,但似乎有几种错误是用户定义函数无法处理的,所以我想它终究不会工作。。。