Skip to content

Instantly share code, notes, and snippets.

@leite
Created January 27, 2016 20:58
Show Gist options
  • Save leite/033b2c9697bf6ab9a578 to your computer and use it in GitHub Desktop.
Save leite/033b2c9697bf6ab9a578 to your computer and use it in GitHub Desktop.
stack trace php
function stackTrace() {
$stack = debug_backtrace();
$output = '';
$stackLen = count($stack);
for ($i = 1; $i < $stackLen; $i++) {
$entry = $stack[$i];
$func = $entry['function'] . '(';
$argsLen = count($entry['args']);
for ($j = 0; $j < $argsLen; $j++) {
$my_entry = $entry['args'][$j];
if (is_string($my_entry)) {
$func .= $my_entry;
}
if ($j < $argsLen - 1) $func .= ', ';
}
$func .= ')';
$entry_file = 'NO_FILE';
if (array_key_exists('file', $entry)) {
$entry_file = $entry['file'];
}
$entry_line = 'NO_LINE';
if (array_key_exists('line', $entry)) {
$entry_line = $entry['line'];
}
$output .= $entry_file . ':' . $entry_line . ' - ' . $func . PHP_EOL;
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment