note 47644 added to function.debug-backtrace

From: Date: Tue, 23 Nov 2004 22:40:56 +0000
Subject: note 47644 added to function.debug-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-80943@lists.php.net to get a copy of this message
And here are my two cents for a useful and good looking backtrace function. <?php function backtrace() { $output = "<div style='text-align: left; font-family: monospace;'>\n"; $output .= "<b>Backtrace:</b><br />\n"; $backtrace = debug_backtrace(); foreach ($backtrace as $bt) { $args = ''; foreach ($bt['args'] as $a) { if (!empty($args)) { $args .= ', '; } switch (gettype($a)) { case 'integer': case 'double': $args .= $a; break; case 'string': $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : ''); $args .= "\"$a\""; break; case 'array': $args .= 'Array('.count($a).')'; break; case 'object': $args .= 'Object('.get_class($a).')'; break; case 'resource': $args .= 'Resource('.strstr($a, '#').')'; break; case 'boolean': $args .= $a ? 'True' : 'False'; break; case 'NULL': $args .= 'Null'; break; default: $args .= 'Unknown'; } } $output .= "<br />\n"; $output .= "<b>file:</b> {$bt['line']} - {$bt['file']}<br />\n"; $output .= "<b>call:</b> {$bt['class']}{$bt['type']}{$bt['function']}($args)<br />\n"; } $output .= "</div>\n"; return $output; } ?> And here's a sample of how the output looks like (the last call is on the top): Backtrace: file: 56 - /tmp/test.php call: backtrace() file: 53 - /tmp/test.php call: test->bar(15.4, Array(4)) file: 61 - /tmp/test.php call: test->test("making new object", True) file: 65 - /tmp/test.php call: foo(Resource(#2), Null) ---- Manual Page -- http://www.php.net/manual/en/function.debug-backtrace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47644 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47644&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47644&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80943) next »