开发者

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

开发者 https://www.devze.com 2022-12-15 02:05 出处:网络
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 applic
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

精彩评论

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