Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
11 changes: 11 additions & 0 deletions tests/Troublemaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}