From 8df1407a11df3e5a8c33c6fae1c522707aefccf3 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 24 Mar 2006 23:06:31 +0000 Subject: Enhanced error context display when a PHP error occurs. --- framework/Data/TDataFieldAccessor.php | 2 +- framework/Exceptions/TErrorHandler.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'framework') diff --git a/framework/Data/TDataFieldAccessor.php b/framework/Data/TDataFieldAccessor.php index a28b9d1f..aa6d7be7 100644 --- a/framework/Data/TDataFieldAccessor.php +++ b/framework/Data/TDataFieldAccessor.php @@ -78,7 +78,7 @@ class TDataFieldAccessor { if(is_array($data) || ($data instanceof ArrayAccess)) { - if(isset($data[$field])) + if(isset($data[$field]) || $data[$field]===null) return $data[$field]; else throw new TInvalidDataValueException('datafieldaccessor_datafield_invalid',$field); diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index 23644fb7..4b42491e 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -207,8 +207,21 @@ class TErrorHandler extends TModule */ protected function displayException($exception) { - $lines=file($exception->getFile()); + $fileName=$exception->getFile(); $errorLine=$exception->getLine(); + if($exception instanceof TPhpErrorException) + { + // if PHP exception, we want to show the 2nd stack level context + // because the 1st stack level is of little use (it's in error handler) + $trace=$exception->getTrace(); + if(isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) + { + $fileName=$trace[0]['file']; + $errorLine=$trace[0]['line']; + } + } + $lines=file($fileName); + $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0; $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines); @@ -227,7 +240,7 @@ class TErrorHandler extends TModule $tokens=array( '%%ErrorType%%' => get_class($exception), '%%ErrorMessage%%' => htmlspecialchars($exception->getMessage()), - '%%SourceFile%%' => htmlspecialchars($exception->getFile()).' ('.$exception->getLine().')', + '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', '%%SourceCode%%' => $source, '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), '%%Version%%' => $_SERVER['SERVER_SOFTWARE'].' PRADO/'.Prado::getVersion(), -- cgit v1.2.3