Skip to content

Commit e9570bf

Browse files
committed
Don't silence fatal errors with @
1 parent 55bd88c commit e9570bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+64
-54
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,6 +39,11 @@
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 */
4348

4449
/*

Zend/zend_execute.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,8 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num,
27702770
}
27712771
} else if (kind == ZEND_LIVE_SILENCE) {
27722772
/* restore previous error_reporting value */
2773-
if (!EG(error_reporting) && Z_LVAL_P(var) != 0) {
2773+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
2774+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
27742775
EG(error_reporting) = Z_LVAL_P(var);
27752776
}
27762777
}

Zend/zend_vm_def.h

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

64056405
ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
64066406

6407-
if (EG(error_reporting)) {
6407+
if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
64086408
do {
6409-
EG(error_reporting) = 0;
6409+
/* Do not silence fatal errors */
6410+
EG(error_reporting) &= E_FATAL_ERRORS;
64106411
if (!EG(error_reporting_ini_entry)) {
64116412
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
64126413
if (zv) {
@@ -6435,7 +6436,8 @@ ZEND_VM_HANDLER(58, ZEND_END_SILENCE, TMP, ANY)
64356436
{
64366437
USE_OPLINE
64376438

6438-
if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
6439+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
6440+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
64396441
EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
64406442
}
64416443
ZEND_VM_NEXT_OPCODE();

Zend/zend_vm_execute.h

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

15321532
ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
15331533

1534-
if (EG(error_reporting)) {
1534+
if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
15351535
do {
1536-
EG(error_reporting) = 0;
1536+
/* Do not silence fatal errors */
1537+
EG(error_reporting) &= E_FATAL_ERRORS;
15371538
if (!EG(error_reporting_ini_entry)) {
15381539
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
15391540
if (zv) {
@@ -18194,7 +18195,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_END_SILENCE_SPEC_TMP_HANDLER(Z
1819418195
{
1819518196
USE_OPLINE
1819618197

18197-
if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
18198+
if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
18199+
&& !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
1819818200
EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
1819918201
}
1820018202
ZEND_VM_NEXT_OPCODE();

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, $vars) {
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, $vars) {
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_variation3.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, $vars) {
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/file/basename_variation3.phpt

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

1313
// Define error handler
1414
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
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/file/basename_variation4.phpt

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

1313
// Define error handler
1414
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
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)