Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
Forked from abtris/exception.php
Created April 23, 2012 15:30
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 lyoshenka/2471688 to your computer and use it in GitHub Desktop.
Save lyoshenka/2471688 to your computer and use it in GitHub Desktop.
<?php
function getExceptionTraceAsString(Exception $exception)
{
$rtn = '';
foreach ($exception->getTrace() as $count => $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,
isset($frame['file']) ? $frame['file'] : 'unknown file',
isset($frame['line']) ? $frame['line'] : 'unknown line',
(isset($frame['class'])) ? $frame['class'].$frame['type'].$frame['function'] : $frame['function'],
$args);
}
return $rtn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment