Skip to content

Instantly share code, notes, and snippets.

@intval
Created Sep 28, 2012
Embed
What would you like to do?
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