Skip to content

Instantly share code, notes, and snippets.

@marcelovani
Last active November 7, 2018 17:19
Show Gist options
  • Save marcelovani/4677f72f3762be783c7abdc13027ce8b to your computer and use it in GitHub Desktop.
Save marcelovani/4677f72f3762be783c7abdc13027ce8b to your computer and use it in GitHub Desktop.
Shorter version of debug_backtrace
function short_backtrace($limit = 0) {
$r = [];
$t = debug_backtrace();
$t = array_slice($t, 1, $limit);
for ($i = 0; $i <= $limit; $i++) {
if (isset($t[$i]['file'])) {
$f = '';
if (isset($t[$i]['function'])) {
$f = ' called ' . $t[$i]['function'] . '()';
}
$r[] = [
'Line' => $t[$i]['file'] . ':' . $t[$i]['line'] . $f,
'With args' => $t[$i]['args'],
];
}
}
return $r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment