From 020cec722d9340e425c6a9565c25d25591f264aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BA=A6=E5=BD=93=E8=8B=97=E5=84=BF?= Date: Tue, 2 Feb 2016 10:36:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Error=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E7=9A=84ErrorContext=E5=8F=82=E6=95=B0=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=89=93=E5=8D=B0ErrorContext=E5=88=B0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Error.php | 4 ++-- library/think/exception/ErrorException.php | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/Error.php b/library/think/Error.php index 6b6218c8..02a92752 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -89,14 +89,14 @@ class Error * @param integer $errline 出错行号 * @return bool true-禁止往下传播已处理过的异常 */ - public static function appError($errno, $errstr, $errfile, $errline) + public static function appError($errno, $errstr, $errfile = null, $errline = 0, array $errcontext = []) { if ($errno & Config::get('exception_ignore_type')) { // 忽略的异常记录到日志 Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notic'); } else { // 将错误信息托管至 think\exception\ErrorException - throw new ErrorException($errno, $errstr, $errfile, $errline); + throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext); // 禁止往下传播已处理过的异常 return true; } diff --git a/library/think/exception/ErrorException.php b/library/think/exception/ErrorException.php index 9e081dfb..caa85c93 100644 --- a/library/think/exception/ErrorException.php +++ b/library/think/exception/ErrorException.php @@ -33,14 +33,17 @@ class ErrorException extends Exception * @param string $message 错误详细信息 * @param string $file 出错文件路径 * @param integer $line 出错行号 + * @param array $context 错误上下文,会包含错误触发处作用域内所有变量的数组 */ - public function __construct($severity, $message, $file, $line) + public function __construct($severity, $message, $file, $line, $context) { $this->severity = $severity; $this->message = $message; $this->file = $file; $this->line = $line; $this->code = 0; + + empty($context) || $this->setData('Error Context', $context); } /**