diff --git a/Zend/tests/bug34786.phpt b/Zend/tests/bug34786.phpt index 18642848d8424..ef0627633fcda 100644 --- a/Zend/tests/bug34786.phpt +++ b/Zend/tests/bug34786.phpt @@ -10,13 +10,13 @@ function bar() { echo "bar: ".error_reporting()."\n"; } -error_reporting(1); +error_reporting(E_WARNING); echo "before: ".error_reporting()."\n"; @foo(1,@bar(),3); echo "after: ".error_reporting()."\n"; ?> --EXPECT-- -before: 1 +before: 2 bar: 0 foo: 0 -after: 1 +after: 2 diff --git a/Zend/zend_errors.h b/Zend/zend_errors.h index 441458c033afe..6fda0f843e3bd 100644 --- a/Zend/zend_errors.h +++ b/Zend/zend_errors.h @@ -39,4 +39,9 @@ #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) #define E_CORE (E_CORE_ERROR | E_CORE_WARNING) +/* Fatal errors that are ignored by the silence operator */ +#define E_FATAL_ERRORS (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE) + +#define E_HAS_ONLY_FATAL_ERRORS(mask) !((mask) & ~E_FATAL_ERRORS) + #endif /* ZEND_ERRORS_H */ diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index edaed2c63f059..c1af0d6f2570f 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3755,7 +3755,8 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num, } } else if (kind == ZEND_LIVE_SILENCE) { /* restore previous error_reporting value */ - if (!EG(error_reporting) && Z_LVAL_P(var) != 0) { + if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting)) + && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) { EG(error_reporting) = Z_LVAL_P(var); } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 9b808a6e120cc..cb1b5b7647e99 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6772,9 +6772,10 @@ ZEND_VM_HANDLER(57, ZEND_BEGIN_SILENCE, ANY, ANY) ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting)); - if (EG(error_reporting)) { + if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) { do { - EG(error_reporting) = 0; + /* Do not silence fatal errors */ + EG(error_reporting) &= E_FATAL_ERRORS; if (!EG(error_reporting_ini_entry)) { zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1); if (zv) { @@ -6803,7 +6804,8 @@ ZEND_VM_HANDLER(58, ZEND_END_SILENCE, TMP, ANY) { USE_OPLINE - if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) { + if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting)) + && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) { EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var)); } ZEND_VM_NEXT_OPCODE(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index f08bb0d3f38f3..c4a222bde9293 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1523,9 +1523,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BEGIN_SILENCE_SPEC_HANDLER(ZEN ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting)); - if (EG(error_reporting)) { + if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) { do { - EG(error_reporting) = 0; + /* Do not silence fatal errors */ + EG(error_reporting) &= E_FATAL_ERRORS; if (!EG(error_reporting_ini_entry)) { zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1); if (zv) { @@ -19660,7 +19661,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_END_SILENCE_SPEC_TMP_HANDLER(Z { USE_OPLINE - if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) { + if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting)) + && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) { EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var)); } ZEND_VM_NEXT_OPCODE(); diff --git a/ext/mbstring/tests/mb_substitute_character_variation1.phpt b/ext/mbstring/tests/mb_substitute_character_variation1.phpt index 68e1ad7ca89ba..69912eca50876 100644 --- a/ext/mbstring/tests/mb_substitute_character_variation1.phpt +++ b/ext/mbstring/tests/mb_substitute_character_variation1.phpt @@ -17,7 +17,7 @@ echo "*** Testing mb_substitute_character() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/spl/tests/class_implements_variation1.phpt b/ext/spl/tests/class_implements_variation1.phpt index 8b122a79f1525..4c70f2b412fb1 100644 --- a/ext/spl/tests/class_implements_variation1.phpt +++ b/ext/spl/tests/class_implements_variation1.phpt @@ -13,7 +13,7 @@ echo "*** Testing class_implements() : variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/spl/tests/class_uses_variation1.phpt b/ext/spl/tests/class_uses_variation1.phpt index fbf476b493642..538c9257e7b3e 100644 --- a/ext/spl/tests/class_uses_variation1.phpt +++ b/ext/spl/tests/class_uses_variation1.phpt @@ -13,7 +13,7 @@ echo "*** Testing class_uses() : variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/array/array_multisort_variation1.phpt b/ext/standard/tests/array/array_multisort_variation1.phpt index 4d7281b92b71d..677a87103fc94 100644 --- a/ext/standard/tests/array/array_multisort_variation1.phpt +++ b/ext/standard/tests/array/array_multisort_variation1.phpt @@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/array/array_multisort_variation2.phpt b/ext/standard/tests/array/array_multisort_variation2.phpt index 994e27ecd04a7..f9a00e9701dc5 100644 --- a/ext/standard/tests/array/array_multisort_variation2.phpt +++ b/ext/standard/tests/array/array_multisort_variation2.phpt @@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/array/array_multisort_variation3.phpt b/ext/standard/tests/array/array_multisort_variation3.phpt index 5939b7bef994f..c625d2a56606e 100644 --- a/ext/standard/tests/array/array_multisort_variation3.phpt +++ b/ext/standard/tests/array/array_multisort_variation3.phpt @@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/file/file_put_contents_variation2.phpt b/ext/standard/tests/file/file_put_contents_variation2.phpt index 1bf30340e4818..5e18ce1948d60 100644 --- a/ext/standard/tests/file/file_put_contents_variation2.phpt +++ b/ext/standard/tests/file/file_put_contents_variation2.phpt @@ -14,7 +14,7 @@ echo "*** Testing file_put_contents() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/file/file_put_contents_variation3.phpt b/ext/standard/tests/file/file_put_contents_variation3.phpt index aaf18c0776558..8adddef2ee758 100644 --- a/ext/standard/tests/file/file_put_contents_variation3.phpt +++ b/ext/standard/tests/file/file_put_contents_variation3.phpt @@ -14,7 +14,7 @@ echo "*** Testing file_put_contents() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; } diff --git a/ext/standard/tests/general_functions/intval_variation1.phpt b/ext/standard/tests/general_functions/intval_variation1.phpt index 086161de6c327..e44bc1db805d2 100644 --- a/ext/standard/tests/general_functions/intval_variation1.phpt +++ b/ext/standard/tests/general_functions/intval_variation1.phpt @@ -12,7 +12,7 @@ echo "*** Testing intval() : usage variation ***\n"; // Define error handler function test_error_handler($err_no, $err_msg, $filename, $linenum) { - if (error_reporting() != 0) { + if (error_reporting() & $err_no) { // report non-silenced errors echo "Error: $err_no - $err_msg, $filename($linenum)\n"; }