views:

46

answers:

1

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_undefined_function( $a, $b );
echo( 'after' );

Outputs:

before
call_undefined_function called
after
+1  A: 

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.

jeroen
I don't think that will handle undefined function errors. I tried `php -r "set_error_handler('var_dump'); d();"` this will fail (error handler won't get called, fatal error message), while `php -r "set_error_handler('var_dump'); echo $undefVar;"` works as expected.
aularon
@aularon, I hadn´t tried it, but it seems there are several kinds of errors that can´t be handled by a user-defined function, so I guess it won´t work after all...
jeroen