@@ -256,22 +256,34 @@ public function renderCallStack(Throwable $t, array $trace = []): string
256256 [],
257257 );
258258
259- $ length = count ($ trace );
260- for ($ i = 0 ; $ i < $ length ; ++$ i ) {
261- $ file = !empty ($ trace [$ i ]['file ' ]) ? $ trace [$ i ]['file ' ] : null ;
262- $ line = !empty ($ trace [$ i ]['line ' ]) ? $ trace [$ i ]['line ' ] : null ;
263- $ class = !empty ($ trace [$ i ]['class ' ]) ? $ trace [$ i ]['class ' ] : null ;
264- $ args = !empty ($ trace [$ i ]['args ' ]) ? $ trace [$ i ]['args ' ] : [];
259+ $ index = 1 ;
260+ if ($ t instanceof ErrorException) {
261+ $ index = 0 ;
262+ }
263+
264+ foreach ($ trace as $ traceItem ) {
265+ $ file = !empty ($ traceItem ['file ' ]) ? $ traceItem ['file ' ] : null ;
266+ $ line = !empty ($ traceItem ['line ' ]) ? $ traceItem ['line ' ] : null ;
267+ $ class = !empty ($ traceItem ['class ' ]) ? $ traceItem ['class ' ] : null ;
268+ $ args = !empty ($ traceItem ['args ' ]) ? $ traceItem ['args ' ] : [];
265269
266270 $ parameters = [];
267271 $ function = null ;
268- if (!empty ($ trace [$ i ]['function ' ]) && $ trace [$ i ]['function ' ] !== 'unknown ' ) {
269- $ function = $ trace [$ i ]['function ' ];
270- if ($ class !== null && !str_contains ($ function , '{closure} ' )) {
271- $ parameters = (new \ReflectionMethod ($ class , $ function ))->getParameters ();
272+ if (!empty ($ traceItem ['function ' ]) && $ traceItem ['function ' ] !== 'unknown ' ) {
273+ $ function = $ traceItem ['function ' ];
274+ if (!str_contains ($ function , '{closure} ' )) {
275+ try {
276+ if ($ class !== null && class_exists ($ class )) {
277+ $ parameters = (new \ReflectionMethod ($ class , $ function ))->getParameters ();
278+ } elseif (function_exists ($ function )) {
279+ $ parameters = (new \ReflectionFunction ($ function ))->getParameters ();
280+ }
281+ } catch (\ReflectionException ) {
282+ // pass
283+ }
272284 }
273285 }
274- $ index = $ i + 2 ;
286+ $ index++ ;
275287
276288 if ($ this ->isVendorFile ($ file )) {
277289 $ vendor [$ index ] = $ this ->renderCallStackItem (
@@ -588,7 +600,7 @@ private function groupVendorCallStackItems(array $items): array
588600 $ groupedItems [$ groupIndex ][$ index ] = $ item ;
589601 }
590602
591- /** @psalm-var array<int, array<int, string>> $groupedItems It's need for Psalm <=4.30 only. */
603+ /** @psalm-var array<int, array<int, string>> $groupedItems It's needed for Psalm <=4.30 only. */
592604
593605 return $ groupedItems ;
594606 }
0 commit comments