diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index 8ca42cb..a03a1e2 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -31,6 +31,13 @@ public function __construct(\Airbrake\Notifier $notifier) */ public function onError($code, $message, $file, $line) { + // If error_reporting() setting has changed since the ErrorHandler was + // installed, respect the new settings. This also respects the + // @-operator (issue #105) + if ((error_reporting() & $code) === 0) { + return false; + } + $this->lastError = [ 'message' => $message, 'file' => $file, diff --git a/tests/ErrorHandlerTest.php b/tests/ErrorHandlerTest.php index 85c5e65..5543e47 100644 --- a/tests/ErrorHandlerTest.php +++ b/tests/ErrorHandlerTest.php @@ -33,6 +33,19 @@ public static function undefinedVarErrorProvider() ]; } + public static function testSuppression() + { + list($notifier, $handler) = self::makeHandlerBoundNotifier(); + + // Cause two errors in a row, but suppress the second one. Verify that + // the notifier's most recent notice corresponds to the first error + // generated. + Troublemaker::echoUndefinedVar(); + @Troublemaker::echoUndefinedIndex(); + + self::testPostsError($notifier); + } + private static function makeHandlerBoundNotifier() { $notifier = new NotifierMock([ diff --git a/tests/Troublemaker.php b/tests/Troublemaker.php index a937fa3..0a1eca8 100644 --- a/tests/Troublemaker.php +++ b/tests/Troublemaker.php @@ -42,4 +42,15 @@ public static function newNestedException() return new \Exception('world', 207, $e); } } + + private static function doEchoUndefinedIndex() + { + $foo = []; + echo $foo[0]; + } + + public static function echoUndefinedIndex() + { + self::doEchoUndefinedIndex(); + } }