开发者

Why's PHP complaining about my register_shutdown_function()? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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'));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜