Merge pull request #2955 from kinglozzer/pulls/default-error-handler

Make default PHP error handler fatal
This commit is contained in:
Simon Welsh 2014-03-16 09:05:52 +13:00
commit 69fa6649ff
2 changed files with 25 additions and 13 deletions

View File

@ -526,8 +526,9 @@ function exceptionHandler($exception) {
/** /**
* Generic callback to catch standard PHP runtime errors thrown by the interpreter * Generic callback to catch standard PHP runtime errors thrown by the interpreter
* or manually triggered with the user_error function. * or manually triggered with the user_error function. Any unknown error codes are treated as
* Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php). * fatal errors.
* Caution: The error levels default to E_ALL if the site is in dev-mode (set in main.php).
* *
* @ignore * @ignore
* @param int $errno * @param int $errno
@ -537,21 +538,23 @@ function exceptionHandler($exception) {
*/ */
function errorHandler($errno, $errstr, $errfile, $errline) { function errorHandler($errno, $errstr, $errfile, $errline) {
switch($errno) { switch($errno) {
case E_ERROR:
case E_CORE_ERROR:
case E_USER_ERROR:
return Debug::fatalHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_WARNING:
case E_CORE_WARNING:
case E_USER_WARNING:
return Debug::warningHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_NOTICE: case E_NOTICE:
case E_USER_NOTICE: case E_USER_NOTICE:
case E_DEPRECATED: case E_DEPRECATED:
case E_USER_DEPRECATED: case E_USER_DEPRECATED:
case E_STRICT: case E_STRICT:
return Debug::noticeHandler($errno, $errstr, $errfile, $errline, debug_backtrace()); return Debug::noticeHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_WARNING:
case E_CORE_WARNING:
case E_USER_WARNING:
case E_RECOVERABLE_ERROR:
return Debug::warningHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
case E_ERROR:
case E_CORE_ERROR:
case E_USER_ERROR:
default:
return Debug::fatalHandler($errno, $errstr, $errfile, $errline, debug_backtrace());
} }
} }

View File

@ -57,9 +57,18 @@ class DebugView extends Object {
E_STRICT => array( E_STRICT => array(
'title' => 'Strict Notice', 'title' => 'Strict Notice',
'class' => 'notice' 'class' => 'notice'
),
E_RECOVERABLE_ERROR => array(
'title' => 'Recoverable Error',
'class' => 'warning'
) )
); );
protected static $unknown_error = array(
'title' => 'Unknown Error',
'class' => 'error'
);
/** /**
* Generate breadcrumb links to the URL path being displayed * Generate breadcrumb links to the URL path being displayed
* *
@ -133,7 +142,7 @@ class DebugView extends Object {
* Write information about the error to the screen * Write information about the error to the screen
*/ */
public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) { public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) {
$errorType = self::$error_types[$errno]; $errorType = isset(self::$error_types[$errno]) ? self::$error_types[$errno] : self::$unknown_error;
$httpRequestEnt = htmlentities($httpRequest, ENT_COMPAT, 'UTF-8'); $httpRequestEnt = htmlentities($httpRequest, ENT_COMPAT, 'UTF-8');
echo '<div class="info ' . $errorType['class'] . '">'; echo '<div class="info ' . $errorType['class'] . '">';
echo "<h1>[" . $errorType['title'] . '] ' . strip_tags($errstr) . "</h1>"; echo "<h1>[" . $errorType['title'] . '] ' . strip_tags($errstr) . "</h1>";