Skip to content

Commit

Permalink
Merge pull request #565 from tanakahisateru/fix-for-php8-error-suppre…
Browse files Browse the repository at this point in the history
…ssor

Fix error suppressor context detection for PHP 8
  • Loading branch information
danielmorell authored May 12, 2022
2 parents 32fdf9f + 43f44d8 commit bfc25e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,28 @@ private function levelTooLow(Level $level): bool
*/
public function shouldSuppress(): bool
{
return error_reporting() === 0 && !$this->reportSuppressed;
// report_suppressed option forces reporting regardless of PHP settings.
if ($this->reportSuppressed) {
return false;
}

$errorReporting = error_reporting();

// For error control operator of PHP 8:
// > Prior to PHP 8.0.0, the error_reporting() called inside the
// > custom error handler always returned 0 if the error was
// > suppressed by the @ operator. As of PHP 8.0.0, it returns
// > the value E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR |
// > E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE.
// https://www.php.net/manual/en/language.operators.errorcontrol.php
if (version_compare(PHP_VERSION, '8.0', 'ge') && $errorReporting === (
E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE
)) {
return true;
}

// PHP 7 or manually disabled case:
return $errorReporting === 0;
}

public function send(EncodedPayload $payload, string $accessToken): ?Response
Expand Down
2 changes: 1 addition & 1 deletion src/DataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function setLocalVarsDump($config)
$fromConfig = isset($config['local_vars_dump']) ? $config['local_vars_dump'] : null;
$this->localVarsDump = self::$defaults->localVarsDump($fromConfig);
if ($this->localVarsDump && !empty(ini_get('zend.exception_ignore_args'))) {
ini_set('zend.exception_ignore_args', 'Off');
ini_set('zend.exception_ignore_args', '0');
assert(empty(ini_get('zend.exception_ignore_args')));
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ public function testReportSuppressed($errorReporting, $configKey, $configValue,
}
}

public function testReportSuppressedActuallySuppressed()
{
$config = new Config(array(
'report_suppressed' => false,
"access_token" => $this->getTestAccessToken()
));
$this->assertFalse($config->shouldSuppress());
$this->assertTrue(@$config->shouldSuppress());
}

public function testFilter()
{
$d = m::mock("Rollbar\Payload\Data")
Expand Down

0 comments on commit bfc25e5

Please sign in to comment.