Skip to content

Commit cf04b7e

Browse files
committed
Merge branch 'error-suppression' into develop
2 parents 5dbd923 + 103117f commit cf04b7e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

collectors/php_errors.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class QM_Collector_PHP_Errors extends QM_DataCollector {
6565
*/
6666
private static $unexpected_error = null;
6767

68+
/**
69+
* @var int
70+
*/
71+
private const NON_SILENT_ERROR_TYPES = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
72+
6873
public function get_storage(): QM_Data {
6974
return new QM_Data_PHP_Errors();
7075
}
@@ -225,7 +230,7 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co
225230

226231
$error_group = 'errors';
227232

228-
if ( 0 === error_reporting() && 0 !== $this->error_reporting ) {
233+
if ( $this->is_error_suppressed() && 0 !== $this->error_reporting ) {
229234
// This is most likely an @-suppressed error
230235
$error_group = 'suppressed';
231236
}
@@ -286,7 +291,17 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co
286291
* @param bool $return_value Error handler return value. Default false.
287292
*/
288293
return apply_filters( 'qm/collect/php_errors_return_value', false );
294+
}
295+
296+
private function is_error_suppressed(): bool {
297+
$current_level = error_reporting();
298+
299+
if ( PHP_MAJOR_VERSION > 7 ) {
300+
// https://www.php.net/manual/en/language.operators.errorcontrol.php
301+
return $current_level === self::NON_SILENT_ERROR_TYPES;
302+
}
289303

304+
return 0 === $current_level;
290305
}
291306

292307
/**

0 commit comments

Comments
 (0)