tags:

views:

126

answers:

3

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) {
        //mail('[email protected]', '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?

A: 

The shutdown function is probably called after all objects have been deconstructed, have you tried:

register_shutdown_function(array('ErrorManager', 'handleFatalError'));
Steve H
I had a ugly typo in my code. Damn.
openfrog
+3  A: 

Because you're attempting to register 'handleFatalError' and the method is called 'handleFatalErrors'.

Er... that's it really.

middaparka
you're right man. %$§!!!
openfrog
+2  A: 

Looks like it should be:

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

Note the s on handleFatalErrors

jimyi