note 112238 added to function.debug-backtrace
| From: | jurchiks101 at gmail dot com | Date: | Tue, 21 May 2013 10:04:57 +0000 |
| Subject: | note 112238 added to function.debug-backtrace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194870@lists.php.net to get a copy of this message | ||
Here's a function I just wrote for getting a nice and comprehensible call trace. It is probably
more resource-intensive than some other alternatives but it is short, understandable, and gives nice
output (Exception->getTraceAsString()).
<?php
function generateCallTrace()
{
$e = new Exception();
$trace = explode("\n", $e->getTraceAsString());
// reverse array to make steps line up chronologically
$trace = array_reverse($trace);
array_shift($trace); // remove {main}
array_pop($trace); // remove call to this method
$length = count($trace);
$result = array();
for ($i = 0; $i < $length; $i++)
{
$result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); //
replace '#someNum' with '$i)', set the right ordering
}
return "\t" . implode("\n\t", $result);
}
?>
Example output:
1) /var/www/test/test.php(15): SomeClass->__construct()
2) /var/www/test/SomeClass.class.php(36): SomeClass->callSomething()
----
Server IP: 69.147.83.199
Probable Submitter: 46.109.97.141
----
Manual Page -- http://php.net/manual/en/function.debug-backtrace.php
Edit -- https://master.php.net/note/edit/112238
Del: integrated -- https://master.php.net/note/delete/112238/integrated
Del: useless -- https://master.php.net/note/delete/112238/useless
Del: bad code -- https://master.php.net/note/delete/112238/bad+code
Del: spam -- https://master.php.net/note/delete/112238/spam
Del: non-english -- https://master.php.net/note/delete/112238/non-english
Del: in docs -- https://master.php.net/note/delete/112238/in+docs
Del: other reasons-- https://master.php.net/note/delete/112238
Reject -- https://master.php.net/note/reject/112238
Search -- https://master.php.net/manage/user-notes.php