Skip to content

Instantly share code, notes, and snippets.

@wallacemaxters
Last active September 5, 2016 12:38
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 wallacemaxters/713abef172b03a18e44954157eb8f933 to your computer and use it in GitHub Desktop.
Save wallacemaxters/713abef172b03a18e44954157eb8f933 to your computer and use it in GitHub Desktop.
Simplify the Trace of an exception. Object references are converted to class string name.
<?php
/**
* Simplify the Trace of an exception. Object references are converted to class string name.
*
* @param Exception|Throwable $e
* @throws \InvalidArgumentException
* @return array
* */
function simple_exception_trace($e)
{
if ($e instanceof \Exception || $e instanceof \Throwable) {
$recursiveObjectName = function ($value) use (&$recursiveObjectName) {
if (is_array($value)) {
return array_map($recursiveObjectName, $value);
}
return is_object($value) ? get_class($value) : $value;
};
$trace = $e->getTrace();
foreach ($trace as &$line) {
isset($line['args']) && $line = $recursiveObjectName($line);
}
return $trace;
}
throw new \InvalidArgumentException('Invalid argument. Expected "Exception" or "Throwable" instance');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment