Created
January 27, 2016 20:58
-
-
Save leite/033b2c9697bf6ab9a578 to your computer and use it in GitHub Desktop.
stack trace php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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