Skip to content

Commit 8388e62

Browse files
Refactor handleError method to properly respect error suppression behavior across PHP versions. Update constants for enhanced error handling clarity.
1 parent 6732f99 commit 8388e62

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/Internal/ErrorHandler.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use const E_CORE_ERROR;
2020
use const E_ERROR;
2121
use const E_PARSE;
22+
use const E_RECOVERABLE_ERROR;
23+
use const E_USER_ERROR;
2224

2325
/**
2426
* Coordinates the flow between error capture, explanation building, state dumping and rendering.
@@ -55,9 +57,14 @@ public function __construct(
5557
*/
5658
public function handleError(int $severity, string $message, ?string $file = null, ?int $line = null): bool
5759
{
58-
// Respect @-operator: if error_reporting() is 0, PHP intends to silence the error.
59-
if (0 === error_reporting()) {
60-
return false;
60+
// Respect @-operator:
61+
// - PHP < 8.0: error_reporting() returns 0 when @ is used
62+
// - PHP >= 8.0: error_reporting() returns E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE (4437)
63+
$errorReporting = error_reporting();
64+
$suppressedMask = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
65+
66+
if (0 === $errorReporting || $errorReporting === $suppressedMask) {
67+
return true; // Error was silenced with @, handle it by doing nothing
6168
}
6269

6370
if (!$this->config->enabled) {

0 commit comments

Comments
 (0)