开发者

Global "method_missing" in PHP? [duplicate]

开发者 https://www.devze.com 2023-01-15 22:21 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Magic functions __call() for functions?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Magic functions __call() for functions?

I can implement __call() to provide method_missing behavior in PHP classes. Is there some way to provide the same functionality in the global scope?

I want something like this:

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

echo( 'before' );
call_开发者_JAVA百科undefined_function( $a, $b );
echo( 'after' );

Outputs:

before
call_undefined_function called
after


You can write your own error handler and use function_exists() in it to generate the message you want. As long as you don´t stop your script in your error handler, execution will continue.

0

精彩评论

暂无评论...
验证码 换一张
取 消