Created
June 4, 2014 07:42
-
-
Save grom358/2372fb6e71465ce6c668 to your computer and use it in GitHub Desktop.
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
<?php | |
function argToString($arg, $maxLength = false) { | |
if (is_null($arg)) { | |
return 'null'; | |
} elseif (is_array($arg)) { | |
return 'Array'; | |
} elseif (is_object($arg)) { | |
return 'Object(' . get_class($arg) . ')'; | |
} elseif (is_bool($arg)) { | |
return $arg ? 'true' : 'false'; | |
} elseif (is_int($arg) || is_double($arg)) { | |
return $arg; | |
} else { | |
$arg = (string) $arg; | |
if ($maxLength && strlen($arg) > $maxLength ) { | |
$arg = substr($arg, 0, $maxLength) . '...'; | |
} | |
return "'" . $arg . "'"; | |
} | |
} | |
function traceToString($trace) { | |
$trace = array_reverse($trace); // Show in reverse order | |
$len = count($trace); | |
$result = ''; | |
foreach($trace as $i => $t) { | |
$result .= '#' . ($len - $i - 1) . ' '; | |
if (!empty($t['class'])) { | |
$result .= $t['class'] . $t['type']; | |
} | |
$result .= $t['function']; | |
$args = array(); | |
if (!empty($t['args'])) { | |
foreach ($t['args'] as $arg) { | |
$args[] = argToString($arg); | |
} | |
} | |
$result .= '(' . implode(', ', $args) . ') at ' | |
. (isset($t['file']) ? $t['file'] : 'Unknown') | |
. ':' . (isset($t['line']) ? $t['line'] : 'Unknown') | |
. "\n"; | |
} | |
return $result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment