Skip to content

Commit 3418351

Browse files
authored
Fix skipping the first trace item when handling a PHP error (#160)
1 parent 640efee commit 3418351

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 4.3.2 under development
44

5-
- no changes in this release.
5+
- Bug #160: Fix skipping the first trace item when handling a PHP error (@vjik)
66

77
## 4.3.1 December 18, 2025
88

src/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function register(): void
135135
}
136136

137137
$backtrace = debug_backtrace(0);
138-
array_shift($backtrace);
138+
unset($backtrace[0]['function'], $backtrace[0]['class'], $backtrace[0]['type'], $backtrace[0]['args']);
139139
throw new ErrorException($message, $severity, $severity, $file, $line, null, $backtrace);
140140
});
141141

tests/ErrorHandlerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ public function testHandleErrorWithCatching(): void
111111
$this->assertInstanceOf(ErrorException::class, $exception);
112112
$this->assertFalse($exception::isFatalError($array));
113113
$this->assertNull($exception->getSolution());
114-
$this->assertNotEmpty($exception->getBacktrace());
114+
115+
$backtrace = $exception->getBacktrace();
116+
$this->assertNotEmpty($backtrace);
117+
$this->assertSame(__FILE__, $backtrace[0]['file']);
118+
$this->assertSame(['file', 'line'], array_keys($backtrace[0]));
115119

116120
$this->errorHandler->unregister();
117121
}

0 commit comments

Comments
 (0)