Forked from Thinkscape/flattenExceptionBacktrace.php
Created
September 6, 2024 18:45
-
-
Save devnix/11932a649c40541c5cde7cd9ba4c2933 to your computer and use it in GitHub Desktop.
Revisions
-
Thinkscape revised this gist
Mar 6, 2015 . 1 changed file with 16 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,18 +3,25 @@ function flattenExceptionBacktrace(\Exception $exception) { $traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace'); $traceProperty->setAccessible(true); $flatten = function(&$value, $key) { if ($value instanceof \Closure) { $closureReflection = new \ReflectionFunction($value); $value = sprintf( '(Closure at %s:%s)', $closureReflection->getFileName(), $closureReflection->getStartLine() ); } elseif (is_object($value)) { $value = sprintf('object(%s)', get_class($value)); } elseif (is_resource($value)) { $value = sprintf('resource(%s)', get_resource_type($value)); } }; do { $trace = $traceProperty->getValue($exception); foreach($trace as &$call) { array_walk_recursive($call['args'], $flatten); } $traceProperty->setValue($exception, $trace); } while($exception = $exception->getPrevious()); -
Thinkscape renamed this gist
Mar 6, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php function flattenExceptionBacktrace(\Exception $exception) { $traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace'); $traceProperty->setAccessible(true); -
Thinkscape created this gist
Mar 6, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ protected static function flattenExceptionBacktrace(Exception $exception) { $traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace'); $traceProperty->setAccessible(true); do { $trace = $traceProperty->getValue($exception); foreach($trace as &$call) { foreach($call['args'] as $key => $value) { if ($value instanceof \Closure) { $call['args'][$key] = '(Closure)'; } elseif (is_object($value) && !method_exists($value, '__toString')) { $call['args'][$key] = sprintf('object(%s)', get_class($value)); } elseif (is_resource($value)) { $call['args'][$key] = sprintf('resource(%s)', get_resource_type($value)); } } } $traceProperty->setValue($exception, $trace); } while($exception = $exception->getPrevious()); $traceProperty->setAccessible(false); }