From 454412905cc3fb29df742f8397a88b1bb439965e Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Sat, 15 Mar 2014 11:52:01 +0000 Subject: [PATCH] Make default PHP error handler fatal --- dev/Debug.php | 27 +++++++++++++++------------ dev/DebugView.php | 11 ++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/dev/Debug.php b/dev/Debug.php index 65d1ed8e6..c87774803 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -526,8 +526,9 @@ function exceptionHandler($exception) { /** * Generic callback to catch standard PHP runtime errors thrown by the interpreter - * or manually triggered with the user_error function. - * Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php). + * or manually triggered with the user_error function. Any unknown error codes are treated as + * fatal errors. + * Caution: The error levels default to E_ALL if the site is in dev-mode (set in main.php). * * @ignore * @param int $errno @@ -537,21 +538,23 @@ function exceptionHandler($exception) { */ function errorHandler($errno, $errstr, $errfile, $errline) { 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_USER_NOTICE: case E_DEPRECATED: case E_USER_DEPRECATED: case E_STRICT: 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()); } } diff --git a/dev/DebugView.php b/dev/DebugView.php index 3904f58b3..56efcfa3b 100644 --- a/dev/DebugView.php +++ b/dev/DebugView.php @@ -57,9 +57,18 @@ class DebugView extends Object { E_STRICT => array( 'title' => 'Strict 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 * @@ -133,7 +142,7 @@ class DebugView extends Object { * Write information about the error to the screen */ 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'); echo '
'; echo "

[" . $errorType['title'] . '] ' . strip_tags($errstr) . "

";