Skip to content

Instantly share code, notes, and snippets.

@samsouder
Created September 18, 2009 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsouder/189099 to your computer and use it in GitHub Desktop.
Save samsouder/189099 to your computer and use it in GitHub Desktop.
A little PHP function to get a succinct string of function backtraces
<?php
// A little PHP function to get a succinct string of function backtraces.
function debug_backtrace_format()
{
$bt = array_slice(debug_backtrace(), 1); // shift off the call to debug_backtrace_format()
return join(', ', array_map(create_function('$a', 'return $a["function"] ."() (". $a["file"] .":". $a["line"] .")";'), $bt));
}
function test()
{
test2();
}
function test2()
{
echo debug_backtrace_format();
}
test();
// OUTPUTS:
// test2() (/Users/ssouder/Desktop/Stubs/stub.php:11), test() (/Users/ssouder/Desktop/Stubs/stub.php:19)
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment