Returns if error is one of fatal type.
public static isFatalError ( array $error ) : boolean | ||
$error | array | error got from error_get_last() |
return | boolean | if error is one of fatal type |
/** * Filter all exceptions. They're logged via ErrorHandler * @inheritdoc */ public static function filterMessages($messages, $levels = 0, $categories = [], $except = []) { $messages = parent::filterMessages($messages, $levels, $categories, $except); foreach ($messages as $i => $message) { $type = explode(':', $message[2]); // shutdown function not working in yii2 yet: https://github.com/yiisoft/yii2/issues/6637 // allow fatal errors exceptions in log messages if (is_array($type) && sizeof($type) == 2 && $type[0] == 'yii\\base\\ErrorException' && ErrorException::isFatalError(['type' => $type[1]])) { continue; } if (is_string($message[0]) && strpos($message[0], 'exception \'') === 0) { unset($messages[$i]); } } return $messages; }
/** * Handles fatal PHP errors */ public function handleFatalError() { 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\\ErrorException', false)) { require_once __DIR__ . '/ErrorException.php'; } $error = error_get_last(); if (ErrorException::isFatalError($error)) { if (!empty($this->_hhvmException)) { $exception = $this->_hhvmException; } else { $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); } $this->exception = $exception; $this->logException($exception); if ($this->discardExistingOutput) { $this->clearOutput(); } $this->renderException($exception); // need to explicitly flush logs because exit() next will terminate the app immediately Yii::getLogger()->flush(true); if (defined('HHVM_VERSION')) { flush(); } exit(1); } }
/** * 处理 PHP 致命错误 */ public function handleFatalError() { 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\\ErrorException', false)) { require_once __DIR__ . '/ErrorException.php'; } $error = error_get_last(); if (ErrorException::isFatalError($error)) { $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); $this->exception = $exception; // use error_log because it's too late to use Yii log // also do not log when on CLI SAPI because message will be sent to STDERR which has already been done by PHP PHP_SAPI === 'cli' or error_log($exception); if ($this->discardExistingOutput) { $this->clearOutput(); } $this->renderException($exception); exit(1); } }
/** * Handles fatal PHP errors */ public function handleFatalError() { 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'; } $error = error_get_last(); if (ErrorException::isFatalError($error)) { $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']); $this->exception = $exception; // use error_log because it's too late to use Yii log error_log($exception); if (($handler = $this->getErrorHandler()) !== null) { $handler->handle($exception); } else { echo $this->renderException($exception); } exit(1); } }