Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kkrieger85/baccbab54a26974d75fb70a23bc6b210 to your computer and use it in GitHub Desktop.
Save kkrieger85/baccbab54a26974d75fb70a23bc6b210 to your computer and use it in GitHub Desktop.
Exception back trace with no truncated strings
<?php
// source: http://stackoverflow.com/questions/1949345/how-can-i-get-the-full-string-of-php-s-gettraceasstring
function getExceptionTraceAsString($exception) {
$rtn = "";
$count = 0;
foreach ($exception->getTrace() as $frame) {
$args = "";
if (isset($frame['args'])) {
$args = array();
foreach ($frame['args'] as $arg) {
if (is_string($arg)) {
$args[] = "'" . $arg . "'";
} elseif (is_array($arg)) {
$args[] = "Array";
} elseif (is_null($arg)) {
$args[] = 'NULL';
} elseif (is_bool($arg)) {
$args[] = ($arg) ? "true" : "false";
} elseif (is_object($arg)) {
$args[] = get_class($arg);
} elseif (is_resource($arg)) {
$args[] = get_resource_type($arg);
} else {
$args[] = $arg;
}
}
$args = join(", ", $args);
}
$rtn .= sprintf( "#%s %s(%s): %s(%s)\n",
$count,
$frame['file'],
$frame['line'],
$frame['function'],
$args );
$count++;
}
return $rtn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment