Skip to content

Don't silence fatal errors with @ #3685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions Zend/tests/bug34786.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions Zend/zend_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 2 additions & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/tests/class_implements_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/tests/class_uses_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_multisort_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_multisort_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_multisort_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down