Handle fatal errors php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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