Why is PHP complaining about my register_shutdown_function ()?

I am trying to register a shutdown function to register a fatal error. Good stuff if it works for my class ...

Inside the method, I do this:

register_shutdown_function(array($this, 'handleFatalError'));

handleFatalError is not static, and it is publicly available:

public function handleFatalErrors() {
    if(is_null($e = error_get_last()) === false) {
        //mail('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 to ...

Why is this invalid callback?

+3
source share
3 answers

Since you are trying to register 'handleFatalError' and the method is called 'handleFatalErrors'.

Uh ... it really is.

+11
source

, :

register_shutdown_function(array($this, 'handleFatalErrors'));

s handleFatalErrors

+5

, , , , :

register_shutdown_function(array('ErrorManager', 'handleFatalError'));
0

Source: https://habr.com/ru/post/1726677/


All Articles