diff --git a/app/Config/core.php b/app/Config/core.php index bb4279cef..78eacd805 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -41,8 +41,6 @@ * * Options: * - * - `fatalErrorHandler` - callback - The callback to handle fatal errors. You can set this to any - * callable type, including anonymous functions. Setting it to false will disable the feature. * - `handler` - callback - The callback to handle errors. You can set this to any callable type, * including anonymous functions. * - `level` - int - The level of errors you are interested in capturing. @@ -51,7 +49,6 @@ * @see ErrorHandler for more information on error handling and configuration. */ Configure::write('Error', array( - 'fatalErrorHandler' => 'ErrorHandler::handleFatalError', 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED, 'trace' => true diff --git a/lib/Cake/Console/Templates/skel/Config/core.php b/lib/Cake/Console/Templates/skel/Config/core.php index 13cdc0e6d..bb904bb1b 100644 --- a/lib/Cake/Console/Templates/skel/Config/core.php +++ b/lib/Cake/Console/Templates/skel/Config/core.php @@ -41,8 +41,6 @@ * * Options: * - * - `fatalErrorHandler` - callback - The callback to handle fatal errors. You can set this to any - * callable type, including anonymous functions. Setting it to false will disable the feature. * - `handler` - callback - The callback to handle errors. You can set this to any callable type, * including anonymous functions. * - `level` - int - The level of errors you are interested in capturing. @@ -51,7 +49,6 @@ * @see ErrorHandler for more information on error handling and configuration. */ Configure::write('Error', array( - 'fatalErrorHandler' => 'ErrorHandler::handleFatalError', 'handler' => 'ErrorHandler::handleError', 'level' => E_ALL & ~E_DEPRECATED, 'trace' => true diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 16b1c0db4..01e0d1ae6 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -913,14 +913,11 @@ class App { return; } - $fatalErrorHandler = Configure::read('Error.fatalErrorHandler'); - if ($fatalErrorHandler === null) { - $fatalErrorHandler = 'ErrorHandler::handleFatalError'; - } - if (!is_callable($fatalErrorHandler)) { + $errorHandler = Configure::read('Error.handler'); + if (!is_callable($errorHandler)) { return; } - call_user_func($fatalErrorHandler, $lastError); + call_user_func($errorHandler, $lastError['type'], $lastError['message'], $lastError['file'], $lastError['line'], array()); } } diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index 8a05b6e2c..0a25b1c27 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -158,6 +158,9 @@ class ErrorHandler { } $errorConfig = Configure::read('Error'); list($error, $log) = self::mapErrorCode($code); + if ($log === LOG_ERROR) { + return self::handleFatalError($code, $description, $file, $line); + } $debug = Configure::read('debug'); if ($debug) { @@ -186,24 +189,28 @@ class ErrorHandler { /** * Generate an error page when some fatal error happens. * - * @param array $error Array with error information. See `error_get_last()` function - * @return void + * @param integer $code Code of error + * @param string $description Error description + * @param string $file File on which error occurred + * @param integer $line Line that triggered the error + * @return boolean */ - public static function handleFatalError($error) { - $logMessage = 'Fatal Error (' . $error['type'] . '): ' . $error['message'] . ' in [' . $error['file'] . ', line ' . $error['line'] . ']'; + public static function handleFatalError($code, $description, $file, $line) { + $logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']'; CakeLog::write(LOG_ERROR, $logMessage); $exceptionHandler = Configure::read('Exception.handler'); if (!is_callable($exceptionHandler)) { - return; + return false; } ob_clean(); if (Configure::read('debug')) { - call_user_func($exceptionHandler, new FatalErrorException($error['message'], 500, $error['file'], $error['line'])); + call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line)); } else { call_user_func($exceptionHandler, new InternalErrorException()); } + return false; } /** diff --git a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php index f59a02e46..246b2eb96 100644 --- a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php @@ -89,7 +89,6 @@ class ErrorHandlerTest extends CakeTestCase { return array( array(E_USER_NOTICE, 'Notice'), array(E_USER_WARNING, 'Warning'), - array(E_USER_ERROR, 'Fatal Error'), ); } @@ -248,11 +247,10 @@ class ErrorHandlerTest extends CakeTestCase { $originalDebugLevel = Configure::read('debug'); $line = __LINE__; - $error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => $line); ob_start(); Configure::write('debug', 1); - ErrorHandler::handleFatalError($error); + ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line); $result = ob_get_clean(); $this->assertContains('Something wrong', $result, 'message missing.'); $this->assertContains(__FILE__, $result, 'filename missing.'); @@ -260,7 +258,7 @@ class ErrorHandlerTest extends CakeTestCase { ob_start(); Configure::write('debug', 0); - ErrorHandler::handleFatalError($error); + ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line); $result = ob_get_clean(); $this->assertNotContains('Something wrong', $result, 'message must not appear.'); $this->assertNotContains(__FILE__, $result, 'filename must not appear.'); @@ -280,10 +278,9 @@ class ErrorHandlerTest extends CakeTestCase { if (file_exists(LOGS . 'error.log')) { unlink(LOGS . 'error.log'); } - $error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => __LINE__); ob_start(); - ErrorHandler::handleFatalError($error); + ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, __LINE__); ob_clean(); $log = file(LOGS . 'error.log');