Skip to content

Commit

Permalink
Fix bug #81591: ignore_repeated_errors broken
Browse files Browse the repository at this point in the history
We should suppress the error if the message is the same, not if
it's different. Apparently we had no test coverage for these
options.
  • Loading branch information
nikic committed Nov 4, 2021
1 parent 462271c commit 4c171ed
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug #81582 (Stringable not implicitly declared if __toString() came
from a trait). (Nikita)
. Fixed bug #81591 (Fatal Error not properly logged in particular cases).
(Nikita)

- GD:
. Fixed bug #71316 (libpng warning from imagecreatefromstring). (cmb)
Expand Down
25 changes: 25 additions & 0 deletions Zend/tests/ignore_repeated_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Test ignore_repeated_errors ini setting
--INI--
ignore_repeated_errors=1
--FILE--
<?php

// Not a repeated error due to different variables names.
$u1 + $u2;

// Repeated error.
$u + $u;

// Not a repeated error, because the line is different.
$u + 1;

?>
--EXPECTF--
Warning: Undefined variable $u1 in %s on line %d

Warning: Undefined variable $u2 in %s on line %d

Warning: Undefined variable $u in %s on line %d

Warning: Undefined variable $u in %s on line %d
24 changes: 24 additions & 0 deletions Zend/tests/ignore_repeated_source.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test ignore_repeated_source ini setting
--INI--
ignore_repeated_errors=1
ignore_repeated_source=1
--FILE--
<?php

// Not a repeated error due to different variables names.
$u1 + $u2;

// Repeated error.
$u + $u;

// Also a repeated error, because we're ignoring the different source.
$u + 1;

?>
--EXPECTF--
Warning: Undefined variable $u1 in %s on line %d

Warning: Undefined variable $u2 in %s on line %d

Warning: Undefined variable $u in %s on line %d
2 changes: 1 addition & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
if (PG(ignore_repeated_errors) && PG(last_error_message)) {
/* no check for PG(last_error_file) is needed since it cannot
* be NULL if PG(last_error_message) is not NULL */
if (zend_string_equals(PG(last_error_message), message)
if (!zend_string_equals(PG(last_error_message), message)
|| (!PG(ignore_repeated_source)
&& ((PG(last_error_lineno) != (int)error_lineno)
|| strcmp(PG(last_error_file), error_filename)))) {
Expand Down

0 comments on commit 4c171ed

Please sign in to comment.