@@ -417,8 +417,8 @@ public function handleError($type, $message, $file, $line)
417
417
self ::$ toStringException = null ;
418
418
} elseif (!$ throw && !($ type & $ level )) {
419
419
if (!isset (self ::$ silencedErrorCache [$ id = $ file .': ' .$ line ])) {
420
- $ lightTrace = $ this ->tracedErrors & $ type ? $ this ->cleanTrace (debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 3 ), $ type , $ file , $ line , false ) : array ();
421
- $ errorAsException = new SilencedErrorContext ($ type , $ file , $ line , $ lightTrace );
420
+ $ lightTrace = $ this ->tracedErrors & $ type ? $ this ->cleanTrace (debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS , 5 ), $ type , $ file , $ line , false ) : array ();
421
+ $ errorAsException = new SilencedErrorContext ($ type , $ file , $ line , isset ( $ lightTrace [ 1 ]) ? array ( $ lightTrace [ 0 ]) : $ lightTrace );
422
422
} elseif (isset (self ::$ silencedErrorCache [$ id ][$ message ])) {
423
423
$ lightTrace = null ;
424
424
$ errorAsException = self ::$ silencedErrorCache [$ id ][$ message ];
@@ -441,7 +441,6 @@ public function handleError($type, $message, $file, $line)
441
441
} else {
442
442
$ errorAsException = new \ErrorException ($ logMessage , 0 , $ type , $ file , $ line );
443
443
444
- // Clean the trace by removing function arguments and the first frames added by the error handler itself.
445
444
if ($ throw || $ this ->tracedErrors & $ type ) {
446
445
$ backtrace = $ errorAsException ->getTrace ();
447
446
$ lightTrace = $ this ->cleanTrace ($ backtrace , $ type , $ file , $ line , $ throw );
@@ -669,6 +668,9 @@ protected function getFatalErrorHandlers()
669
668
);
670
669
}
671
670
671
+ /**
672
+ * Cleans the trace by removing function arguments and the frames added by the error handler and DebugClassLoader.
673
+ */
672
674
private function cleanTrace ($ backtrace , $ type , $ file , $ line , $ throw )
673
675
{
674
676
$ lightTrace = $ backtrace ;
@@ -679,6 +681,13 @@ private function cleanTrace($backtrace, $type, $file, $line, $throw)
679
681
break ;
680
682
}
681
683
}
684
+ if (class_exists (DebugClassLoader::class, false )) {
685
+ for ($ i = \count ($ lightTrace ) - 2 ; 0 < $ i ; --$ i ) {
686
+ if (DebugClassLoader::class === ($ lightTrace [$ i ]['class ' ] ?? null )) {
687
+ array_splice ($ lightTrace , --$ i , 2 );
688
+ }
689
+ }
690
+ }
682
691
if (!($ throw || $ this ->scopedErrors & $ type )) {
683
692
for ($ i = 0 ; isset ($ lightTrace [$ i ]); ++$ i ) {
684
693
unset($ lightTrace [$ i ]['args ' ], $ lightTrace [$ i ]['object ' ]);
0 commit comments