Skip to content

Commit

Permalink
Fix fatal error handling.
Browse files Browse the repository at this point in the history
Fatal error handling used to reference configure values that no longer
existed.

Move the fatal error handling in the error handling classes as it makes
more sense there. Doing this also allows far more code re-use than
before.
  • Loading branch information
markstory committed Sep 7, 2013
1 parent cb0b9c6 commit 275a618
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
28 changes: 0 additions & 28 deletions lib/Cake/Core/App.php
Expand Up @@ -664,34 +664,6 @@ public static function shutdown() {
if (static::$_objectCacheChange) {
Cache::write('object_map', static::$_objects, '_cake_core_');
}
static::_checkFatalError();
}

/**
* Check if a fatal error happened and trigger the configured handler if configured
*
* @return void
*/
protected static function _checkFatalError() {
$lastError = error_get_last();
if (!is_array($lastError)) {
return;
}

list(, $log) = ErrorHandler::mapErrorCode($lastError['type']);
if ($log !== LOG_ERR) {
return;
}

if (PHP_SAPI === 'cli') {
$errorHandler = Configure::read('Error.consoleHandler');
} else {
$errorHandler = Configure::read('Error.handler');
}
if (!is_callable($errorHandler)) {
return;
}
call_user_func($errorHandler, $lastError['type'], $lastError['message'], $lastError['file'], $lastError['line'], array());
}

}
20 changes: 20 additions & 0 deletions lib/Cake/Error/BaseErrorHandler.php
Expand Up @@ -64,6 +64,26 @@ public function register() {
error_reporting($level);
set_error_handler([$this, 'handleError'], $level);
set_exception_handler([$this, 'handleException']);
register_shutdown_function(function () {
$error = error_get_last();
if (!is_array($error)) {
return;
}
$fatals = [
E_USER_ERROR,
E_ERROR,
E_PARSE,
];
if (!in_array($error['type'], $fatals, true)) {
return;
}
$this->handleFatalError(
$error['type'],
$error['message'],
$error['file'],
$error['line']
);
});
}

/**
Expand Down

0 comments on commit 275a618

Please sign in to comment.