Skip to content

Commit cb1784c

Browse files
committed
Don't silence fatal errors with @
1 parent 6e3600f commit cb1784c

14 files changed

+29
-19
lines changed

Zend/tests/bug34786.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ function bar() {
1010
echo "bar: ".error_reporting()."\n";
1111
}
1212

13-
error_reporting(1);
13+
error_reporting(E_WARNING);
1414
echo "before: ".error_reporting()."\n";
1515
@foo(1,@bar(),3);
1616
echo "after: ".error_reporting()."\n";
1717
?>
1818
--EXPECT--
19-
before: 1
19+
before: 2
2020
bar: 0
2121
foo: 0
22-
after: 1
22+
after: 2

Zend/zend_errors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@
3939
#define E_ALL (E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_RECOVERABLE_ERROR | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)
4040
#define E_CORE (E_CORE_ERROR | E_CORE_WARNING)
4141

42+
/* Fatal errors that are ignored by the silence operator */
43+
#define E_FATAL_ERRORS (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE)
44+
45+
#define E_HAS_ONLY_FATAL_ERRORS(mask) !((mask) & ~E_FATAL_ERRORS)
46+
4247
#endif /* ZEND_ERRORS_H */

Zend/zend_execute.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3755,7 +3755,8 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num,
37553755
}
37563756
} else if (kind == ZEND_LIVE_SILENCE) {
37573757
/* restore previous error_reporting value */
3758-
if (!EG(error_reporting) && Z_LVAL_P(var) != 0) {
3758+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
3759+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
37593760
EG(error_reporting) = Z_LVAL_P(var);
37603761
}
37613762
}

Zend/zend_vm_def.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6772,9 +6772,10 @@ ZEND_VM_HANDLER(57, ZEND_BEGIN_SILENCE, ANY, ANY)
67726772

67736773
ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
67746774

6775-
if (EG(error_reporting)) {
6775+
if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
67766776
do {
6777-
EG(error_reporting) = 0;
6777+
/* Do not silence fatal errors */
6778+
EG(error_reporting) &= E_FATAL_ERRORS;
67786779
if (!EG(error_reporting_ini_entry)) {
67796780
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
67806781
if (zv) {
@@ -6803,7 +6804,8 @@ ZEND_VM_HANDLER(58, ZEND_END_SILENCE, TMP, ANY)
68036804
{
68046805
USE_OPLINE
68056806

6806-
if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
6807+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
6808+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
68076809
EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
68086810
}
68096811
ZEND_VM_NEXT_OPCODE();

Zend/zend_vm_execute.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BEGIN_SILENCE_SPEC_HANDLER(ZEN
15231523

15241524
ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
15251525

1526-
if (EG(error_reporting)) {
1526+
if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
15271527
do {
1528-
EG(error_reporting) = 0;
1528+
/* Do not silence fatal errors */
1529+
EG(error_reporting) &= E_FATAL_ERRORS;
15291530
if (!EG(error_reporting_ini_entry)) {
15301531
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
15311532
if (zv) {
@@ -19660,7 +19661,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_END_SILENCE_SPEC_TMP_HANDLER(Z
1966019661
{
1966119662
USE_OPLINE
1966219663

19663-
if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
19664+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
19665+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
1966419666
EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
1966519667
}
1966619668
ZEND_VM_NEXT_OPCODE();

ext/mbstring/tests/mb_substitute_character_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ echo "*** Testing mb_substitute_character() : usage variation ***\n";
1717

1818
// Define error handler
1919
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
20-
if (error_reporting() != 0) {
20+
if (error_reporting() & $err_no) {
2121
// report non-silenced errors
2222
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
2323
}

ext/spl/tests/class_implements_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo "*** Testing class_implements() : variation ***\n";
1313

1414
// Define error handler
1515
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
16-
if (error_reporting() != 0) {
16+
if (error_reporting() & $err_no) {
1717
// report non-silenced errors
1818
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
1919
}

ext/spl/tests/class_uses_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo "*** Testing class_uses() : variation ***\n";
1313

1414
// Define error handler
1515
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
16-
if (error_reporting() != 0) {
16+
if (error_reporting() & $err_no) {
1717
// report non-silenced errors
1818
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
1919
}

ext/standard/tests/array/array_multisort_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n";
1212

1313
// Define error handler
1414
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
15-
if (error_reporting() != 0) {
15+
if (error_reporting() & $err_no) {
1616
// report non-silenced errors
1717
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
1818
}

ext/standard/tests/array/array_multisort_variation2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n";
1212

1313
// Define error handler
1414
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
15-
if (error_reporting() != 0) {
15+
if (error_reporting() & $err_no) {
1616
// report non-silenced errors
1717
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
1818
}

0 commit comments

Comments
 (0)