Skip to content

Instantly share code, notes, and snippets.

@grom358
Created June 4, 2014 07:42
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 grom358/2372fb6e71465ce6c668 to your computer and use it in GitHub Desktop.
Save grom358/2372fb6e71465ce6c668 to your computer and use it in GitHub Desktop.
<?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