Skip to content

Instantly share code, notes, and snippets.

@intval
Created September 28, 2012 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intval/3798792 to your computer and use it in GitHub Desktop.
Save intval/3798792 to your computer and use it in GitHub Desktop.
Handle fatal errors php
<?php
function the_last_function()
{
static $haltCodes = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR);
$error = error_get_last();
if ($error && in_array($error['type'], $haltCodes))
{
// Discard all output first
ob_clean();
echo 'we had a fatal error, sorry';
// logErrorSomewhere()
}
else
{
echo 'either we had nor error, or no fatal error bumped';
}
}
register_shutdown_function('the_last_function');
// start output buffering
ob_start();
echo 'Do something <br/>';
trigger_error('some error', E_USER_ERROR);
echo 'Script stopped. This will not be printed <br/>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment