From 12e5f62c0bf91bb97935ce08657997bbc8294700 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 14 Jun 2013 10:49:50 +0200 Subject: [PATCH] Errorhandler, manually load classes load ErrorException manually because autoloading them will not work when error occurs while autoloading a class --- framework/yii/base/Application.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index e94ca65..0f78cb6 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -347,8 +347,7 @@ abstract class Application extends Module /** * Handles uncaught PHP exceptions. * - * This method is implemented as a PHP exception handler. It requires - * that constant YII_ENABLE_ERROR_HANDLER be defined true. + * This method is implemented as a PHP exception handler. * * @param \Exception $exception the exception that is not caught */ @@ -394,6 +393,14 @@ abstract class Application extends Module public function handleError($code, $message, $file, $line) { if (error_reporting() !== 0) { + // load ErrorException manually here because autoloading them will not work + // when error occurs while autoloading a class + if (!class_exists('\\yii\\base\\Exception', false)) { + require_once(__DIR__ . '/Exception.php'); + } + if (!class_exists('\\yii\\base\\ErrorException', false)) { + require_once(__DIR__ . '/ErrorException.php'); + } $exception = new ErrorException($message, $code, $code, $file, $line); // in case error appeared in __toString method we can't throw any exception @@ -402,6 +409,7 @@ abstract class Application extends Module foreach ($trace as $frame) { if ($frame['function'] == '__toString') { $this->handleException($exception); + return; } } @@ -418,6 +426,14 @@ abstract class Application extends Module if (ErrorException::isFatalError($error)) { unset($this->_memoryReserve); + // load ErrorException manually here because autoloading them will not work + // when error occurs while autoloading a class + if (!class_exists('\\yii\\base\\Exception', false)) { + require_once(__DIR__ . '/Exception.php'); + } + if (!class_exists('\\yii\\base\\ErrorException', false)) { + require_once(__DIR__ . '/ErrorException.php'); + } $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); // use error_log because it's too late to use Yii log error_log($exception);