Forked from Thinkscape/flattenExceptionBacktrace.php
Last active
July 4, 2021 10:44
Revisions
-
nh-mike revised this gist
Apr 4, 2019 . 1 changed file with 1 addition 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 @@ -33,7 +33,7 @@ function flattenExceptionBacktrace(\Throwable $exception) { array_walk_recursive($call['args'], $flatten); } $traceProperty->setValue($exception, $trace); } while($previousexception = $exception->getPrevious()); $traceProperty->setAccessible(false); } -
nh-mike revised this gist
Apr 4, 2019 . 1 changed file with 6 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 @@ -22,13 +22,18 @@ function flattenExceptionBacktrace(\Throwable $exception) { } }; $previousexception = $exception; do { if ($previousexception === NULL) { break; } $exception = $previousexception; $trace = $traceProperty->getValue($exception); foreach($trace as &$call) { array_walk_recursive($call['args'], $flatten); } $traceProperty->setValue($exception, $trace); } while($nextexception = $exception->getPrevious()); $traceProperty->setAccessible(false); } -
nh-mike revised this gist
Mar 28, 2019 . 1 changed file with 6 additions and 2 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 @@ -1,6 +1,10 @@ <?php function flattenExceptionBacktrace(\Throwable $exception) { if ($exception instanceof \Exception) { $traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace'); } else { $traceProperty = (new \ReflectionClass('Error'))->getProperty('trace'); } $traceProperty->setAccessible(true); $flatten = function(&$value, $key) { -
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); }