Re: [PHP] Uncatchable errors

2011-06-13 Thread David Harkness
On Mon, Jun 13, 2011 at 12:52 PM, Paul M Foster 
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


Re: [PHP] Uncatchable errors

2011-06-13 Thread Stuart Dallas
On Mon, Jun 13, 2011 at 8:52 PM, Paul M Foster 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()? In my case, the error handler emails me
> a summary and trace of the error. Any way to have things like parse
> errors do the same thing?
>
> Pointers to prior threads would do fine.
>

The only way to do this is to run your PHP script inside another process
(PHP or otherwise), piping the output accordingly so you can detect errors
that cannot be caught by the error handler.

However, statically detectable issues such as parse errors should never get
as far as a dynamic environment outside of your development machine, so I
would question why you have this requirement.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/