@@ -267,22 +267,34 @@ public function renderCallStack(Throwable $t, array $trace = []): string
267267 [],
268268 );
269269
270- $ length = count ($ trace );
271- for ($ i = 0 ; $ i < $ length ; ++$ i ) {
272- $ file = !empty ($ trace [$ i ]['file ' ]) ? $ trace [$ i ]['file ' ] : null ;
273- $ line = !empty ($ trace [$ i ]['line ' ]) ? $ trace [$ i ]['line ' ] : null ;
274- $ class = !empty ($ trace [$ i ]['class ' ]) ? $ trace [$ i ]['class ' ] : null ;
275- $ args = !empty ($ trace [$ i ]['args ' ]) ? $ trace [$ i ]['args ' ] : [];
270+ $ index = 1 ;
271+ if ($ t instanceof ErrorException) {
272+ $ index = 0 ;
273+ }
274+
275+ foreach ($ trace as $ traceItem ) {
276+ $ file = !empty ($ traceItem ['file ' ]) ? $ traceItem ['file ' ] : null ;
277+ $ line = !empty ($ traceItem ['line ' ]) ? $ traceItem ['line ' ] : null ;
278+ $ class = !empty ($ traceItem ['class ' ]) ? $ traceItem ['class ' ] : null ;
279+ $ args = !empty ($ traceItem ['args ' ]) ? $ traceItem ['args ' ] : [];
276280
277281 $ parameters = [];
278282 $ function = null ;
279- if (!empty ($ trace [$ i ]['function ' ]) && $ trace [$ i ]['function ' ] !== 'unknown ' ) {
280- $ function = $ trace [$ i ]['function ' ];
281- if ($ class !== null && !str_contains ($ function , '{closure} ' )) {
282- $ parameters = (new \ReflectionMethod ($ class , $ function ))->getParameters ();
283+ if (!empty ($ traceItem ['function ' ]) && $ traceItem ['function ' ] !== 'unknown ' ) {
284+ $ function = $ traceItem ['function ' ];
285+ if (!str_contains ($ function , '{closure} ' )) {
286+ try {
287+ if ($ class !== null && class_exists ($ class )) {
288+ $ parameters = (new \ReflectionMethod ($ class , $ function ))->getParameters ();
289+ } elseif (function_exists ($ function )) {
290+ $ parameters = (new \ReflectionFunction ($ function ))->getParameters ();
291+ }
292+ } catch (\ReflectionException ) {
293+ // pass
294+ }
283295 }
284296 }
285- $ index = $ i + 2 ;
297+ $ index++ ;
286298
287299 if ($ this ->isVendorFile ($ file )) {
288300 $ vendor [$ index ] = $ this ->renderCallStackItem (
@@ -599,7 +611,7 @@ private function groupVendorCallStackItems(array $items): array
599611 $ groupedItems [$ groupIndex ][$ index ] = $ item ;
600612 }
601613
602- /** @psalm-var array<int, array<int, string>> $groupedItems It's need for Psalm <=4.30 only. */
614+ /** @psalm-var array<int, array<int, string>> $groupedItems It's needed for Psalm <=4.30 only. */
603615
604616 return $ groupedItems ;
605617 }
0 commit comments