Re: Uncatchable errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 13, 2011 at 12:52 PM, Paul M Foster <paulf@xxxxxxxxxxxxxxxxx>
wrote:
>
> There's certain class of errors which happen before any error-handler
> (set_error_handler) can catch them, like parse errors and such. Is there
> a way to have these generate the same type of response as the errors
> handled by set_error_handler()?

You can use register_shutdown_function() [1] and error_get_last() [2] to
check if the last error type is one of the fatal errors. Here's a simple
example:

    function shutdown() {
        $error = error_get_last();
        if ($error['type'] === E_ERROR) {
            // fatal error has occured
        }
    }

    register_shutdown_function('shutdown');

There are at least four fatal error types to check for. See [3] and [4] for
the list and links to more examples.

Peace,
David

[1] http://php.net/manual/en/function.register-shutdown-function.php
[2] http://php.net/manual/en/function.error-get-last.php
[3]
http://stackoverflow.com/questions/3108361/php-is-there-a-way-to-redirect-to-an-error-page-in-register-shutdown-function
[4]
http://stackoverflow.com/questions/4410632/handle-fatal-errors-in-php-using-register-shutdown-function

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux