Why's PHP complaining about my register_shutdown_function()? [closed]
I try to register a shutdown function to log an fatal error. Nice stuff, if it would work for my class...
Inside a method I do this:
register_shutdown_function(array($this, 'handleFatalError'));
handleFatalError is not static, and it's public:
public function handleFatalErrors() {
if(is_null($e = error_get_last()) === false) {
//m开发者_StackOverflow中文版ail('your.email@example.com', 'Error from auto_prepend', print_r($e, true));
}
}
PHP says:
Warning: register_shutdown_function() [function.register-shutdown-function]: Invalid shutdown callback 'ErrorManager::handleFatalError' passed in ...
Why's that an invalid callback?
Because you're attempting to register 'handleFatalError' and the method is called 'handleFatalErrors'.
Er... that's it really.
Looks like it should be:
register_shutdown_function(array($this, 'handleFatalErrors'));
Note the s on handleFatalErrors
The shutdown function is probably called after all objects have been deconstructed, have you tried:
register_shutdown_function(array('ErrorManager', 'handleFatalError'));
精彩评论