From 51629974c1cf38d1fa482b1090dd498718d450a9 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 23 Dec 2025 12:18:24 +0300 Subject: [PATCH] Fix skipping the first trace item when handling a PHP error --- CHANGELOG.md | 2 +- src/ErrorHandler.php | 2 +- tests/ErrorHandlerTest.php | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be9f384..098b765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 4.3.2 under development -- no changes in this release. +- Bug #160: Fix skipping the first trace item when handling a PHP error (@vjik) ## 4.3.1 December 18, 2025 diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index f9c4aa0..dc26b09 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -135,7 +135,7 @@ public function register(): void } $backtrace = debug_backtrace(0); - array_shift($backtrace); + unset($backtrace[0]['function'], $backtrace[0]['class'], $backtrace[0]['type'], $backtrace[0]['args']); throw new ErrorException($message, $severity, $severity, $file, $line, null, $backtrace); }); diff --git a/tests/ErrorHandlerTest.php b/tests/ErrorHandlerTest.php index a315bb5..0891104 100644 --- a/tests/ErrorHandlerTest.php +++ b/tests/ErrorHandlerTest.php @@ -111,7 +111,11 @@ public function testHandleErrorWithCatching(): void $this->assertInstanceOf(ErrorException::class, $exception); $this->assertFalse($exception::isFatalError($array)); $this->assertNull($exception->getSolution()); - $this->assertNotEmpty($exception->getBacktrace()); + + $backtrace = $exception->getBacktrace(); + $this->assertNotEmpty($backtrace); + $this->assertSame(__FILE__, $backtrace[0]['file']); + $this->assertSame(['file', 'line'], array_keys($backtrace[0])); $this->errorHandler->unregister(); }