diff --git a/core/Debug.php b/core/Debug.php index 9f1258f07..43e9abb4a 100644 --- a/core/Debug.php +++ b/core/Debug.php @@ -6,7 +6,37 @@ */ /** - * Supports debugging and core error handling via static methods. + * Supports debugging and core error handling. + * + * Attaches custom methods to the default + * error handling hooks in PHP. Currently, three levels + * of error are supported: + * + * - Notice + * - Warning + * - Error + * + * Notice level errors are currently unsupported, and will be passed + * directly to the normal PHP error output. + * + * Uncaught exceptions are currently passed to the debug + * reporter as standard PHP errors. + * + * There are four different types of error handler supported by the + * Debug class: + * + * - Friendly + * - Fatal + * - Logger + * - Emailer + * + * Currently, only Friendly, Fatal, and Emailer handlers are implemented. + * + * @todo port header/footer wrapping code to external reporter class + * @todo add support for user defined config: Debug::die_on_notice(true | false) + * @todo add appropriate handling for E_NOTICE and E_USER_NOTICE levels + * @todo better way of figuring out the error context to display in highlighted source + * @todo implement error logger handler * * @package sapphire * @subpackage core @@ -39,7 +69,7 @@ class Debug { if(Director::is_ajax()) echo "Debug ($caller[class]$caller[type]$caller[function]() in line $caller[line] of " . basename($caller['file']) . ")\n"; else - echo "
'; + print_r($val); + echo ''; + } static function text($val) { if(is_object($val)) { @@ -123,7 +159,8 @@ class Debug { * @todo can this be moved into loadErrorHandlers? */ static function loadFatalErrorHandler() { - set_error_handler('errorHandler', (E_ALL ^ E_NOTICE) ^ E_USER_NOTICE); + //set_error_handler('errorHandler', (E_ALL ^ E_NOTICE) ^ E_USER_NOTICE); + set_error_handler('errorHandler', E_ALL); set_exception_handler('exceptionHandler'); } @@ -164,22 +201,50 @@ class Debug { static function showError($errno, $errstr, $errfile, $errline, $errcontext) { if(!headers_sent()) header("HTTP/1.0 500 Internal server error"); - if(Director::is_ajax()) { echo "ERROR:Error $errno: $errstr\n At l$errline in $errfile\n"; Debug::backtrace(); - } else { - echo "
FATAL ERROR: $errstr
\n At line $errline in $errfile
\n
\n
Line $errline in $errfile
"; + echo ''; + $offset++; + foreach($lines as $line) { + $line = htmlentities($line); + if ($offset == $errline) { + echo "$offset $line"; + } else { + echo "$offset $line"; + } + $offset++; + } + echo '
" . self::full_func_name($item,true) . "\n
\n";
- $result .= isset($item['line']) ? "line $item[line] of " : '';
+ if ($item['function'] == 'user_error') {
+ $name = $item['args'][0];
+ } else {
+ $name = self::full_func_name($item,true);
+ }
+ $result .= "