note 47644 deleted from function.debug-backtrace by cmb

From: Date: Sun, 17 Nov 2019 08:30:26 +0000
Subject: note 47644 deleted from function.debug-backtrace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213063@lists.php.net to get a copy of this message
Note Submitter: diz at ysagoon dot com ---- 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)

« previous php.notes (#213063) next »