From 84a3cd29d0c7fd1afc47bfbfd75ffff5e30a2f35 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 8 Jan 2008 03:00:38 +0000 Subject: [PATCH] Fix stack trace on objects that don't extend the Object class git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47716 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Debug.php | 58 ++++++++++++++++++++++++++++-------------- tests/SapphireTest.php | 2 +- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/core/Debug.php b/core/Debug.php index a8e6a7757..703f416c0 100644 --- a/core/Debug.php +++ b/core/Debug.php @@ -48,26 +48,34 @@ class Debug { } static function text($val) { - if(is_object($val) && $val->hasMethod('debug')) { - return $val->debug(); - } else { - if(is_array($val)) { - $result = "\n"; - - } else if (is_object($val)) { - $val = var_export($val, true); + if(is_object($val)) { + if(method_exists($val, 'hasMethod')) { + $hasDebugMethod = $val->hasMethod('debug'); } else { - if(true || !Director::is_ajax()) { - $val = "
" . htmlentities($val) . "
\n"; - } + $hasDebugMethod = method_exists($val, 'debug'); + } + + if($hasDebugMethod) { + return $val->debug(); } - - return $val; } + + if(is_array($val)) { + $result = "\n"; + + } else if (is_object($val)) { + $val = var_export($val, true); + } else { + if(true || !Director::is_ajax()) { + $val = "
" . htmlentities($val) . "
\n"; + } + } + + return $val; } /** @@ -144,6 +152,7 @@ class Debug { echo "

FATAL ERROR: $errstr
\n At line $errline in $errfile
\n
\n

\n"; Debug::backtrace(); + //Debug::show(debug_backtrace()); echo "

Context

\n"; Debug::show($errcontext); @@ -240,7 +249,7 @@ class Debug { while( $bt && in_array(self::full_func_name($bt[0]), $ignoredFunctions) ) { array_shift($bt); } - + $result = ""; foreach($bt as $item) { if(Director::is_ajax() && !$ignoreAjax) { @@ -254,6 +263,8 @@ class Debug { } } + $result .= 'hi'; + echo $result; if($returnVal) return $result; else echo $result; } @@ -268,7 +279,16 @@ class Debug { if(isset($item['function'])) $funcName .= $item['function']; if($showArgs && isset($item['args'])) { - @$funcName .= "(" . implode(",", (array)$item['args']) .")"; + $args = array(); + foreach($item['args'] as $arg) { + if(!is_object($arg) || method_exists($arg, '__toString')) { + $args[] = (string) $arg; + } else { + $args[] = get_class($arg); + } + } + + $funcName .= "(" . implode(",", $args) .")"; } return $funcName; diff --git a/tests/SapphireTest.php b/tests/SapphireTest.php index bd6a3380d..17077b240 100644 --- a/tests/SapphireTest.php +++ b/tests/SapphireTest.php @@ -167,4 +167,4 @@ class SapphireTest extends PHPUnit_Framework_TestCase { class SapphireTest extends Object {} } -?> \ No newline at end of file +?>