@@ -1286,7 +1286,7 @@ PHPAPI void php_html_puts(const char *str, size_t size)
12861286}
12871287/* }}} */
12881288
1289- static void clear_last_error (void ) {
1289+ static void clear_last_error (bool clear_repeated_errors ) {
12901290 if (PG (last_error_message )) {
12911291 zend_string_release (PG (last_error_message ));
12921292 PG (last_error_message ) = NULL ;
@@ -1295,6 +1295,16 @@ static void clear_last_error(void) {
12951295 zend_string_release (PG (last_error_file ));
12961296 PG (last_error_file ) = NULL ;
12971297 }
1298+ if (clear_repeated_errors ) {
1299+ for (uint32_t i = 0 ; i < 32 ; i ++ ) {
1300+ if (PG (repeated_error_messages )[i ]) {
1301+ zend_string_release (PG (repeated_error_messages )[i ]);
1302+ PG (repeated_error_messages )[i ] = NULL ;
1303+ zend_string_release (PG (repeated_error_files )[i ]);
1304+ PG (repeated_error_files )[i ] = NULL ;
1305+ }
1306+ }
1307+ }
12981308}
12991309
13001310#if ZEND_DEBUG
@@ -1328,16 +1338,20 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
13281338{
13291339 bool display ;
13301340 int type = orig_type & E_ALL ;
1341+ uint32_t repeated_error_index = 0 ;
13311342 zend_string * backtrace = ZSTR_EMPTY_ALLOC ();
1343+ zend_string * repeated_error_file = error_filename ? error_filename : ZSTR_KNOWN (ZEND_STR_UNKNOWN_CAPITALIZED );
1344+
1345+ while (repeated_error_index < 31 && !(type & (1U << repeated_error_index ))) {
1346+ repeated_error_index ++ ;
1347+ }
13321348
13331349 /* check for repeated errors to be ignored */
1334- if (PG (ignore_repeated_errors ) && PG (last_error_message )) {
1335- /* no check for PG(last_error_file) is needed since it cannot
1336- * be NULL if PG(last_error_message) is not NULL */
1337- if (!zend_string_equals (PG (last_error_message ), message )
1350+ if (PG (ignore_repeated_errors ) && PG (repeated_error_messages )[repeated_error_index ]) {
1351+ if (!zend_string_equals (PG (repeated_error_messages )[repeated_error_index ], message )
13381352 || (!PG (ignore_repeated_source )
1339- && ((PG (last_error_lineno ) != error_lineno )
1340- || !zend_string_equals (PG (last_error_file ), error_filename )))) {
1353+ && ((PG (repeated_error_linenos )[ repeated_error_index ] != ( int ) error_lineno )
1354+ || !zend_string_equals (PG (repeated_error_files )[ repeated_error_index ], repeated_error_file )))) {
13411355 display = 1 ;
13421356 } else {
13431357 display = 0 ;
@@ -1374,7 +1388,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
13741388
13751389 /* store the error if it has changed */
13761390 if (display ) {
1377- clear_last_error ();
1391+ clear_last_error (false );
13781392 if (!error_filename ) {
13791393 error_filename = ZSTR_KNOWN (ZEND_STR_UNKNOWN_CAPITALIZED );
13801394 }
@@ -1384,6 +1398,17 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c
13841398 PG (last_error_lineno ) = error_lineno ;
13851399 }
13861400
1401+ if (!PG (repeated_error_messages )[repeated_error_index ]
1402+ || display ) {
1403+ if (PG (repeated_error_messages )[repeated_error_index ]) {
1404+ zend_string_release (PG (repeated_error_messages )[repeated_error_index ]);
1405+ zend_string_release (PG (repeated_error_files )[repeated_error_index ]);
1406+ }
1407+ PG (repeated_error_linenos )[repeated_error_index ] = error_lineno ;
1408+ PG (repeated_error_messages )[repeated_error_index ] = zend_string_copy (message );
1409+ PG (repeated_error_files )[repeated_error_index ] = zend_string_copy (repeated_error_file );
1410+ }
1411+
13871412 /* Discarding the output buffers frees every handler on the stack, which is
13881413 * not safe while one of them is running */
13891414 if (zend_alloc_in_memory_limit_error_reporting ()
@@ -1708,7 +1733,7 @@ static zval *php_get_configuration_directive_for_zend(zend_string *name)
17081733/* {{{ php_free_request_globals */
17091734static void php_free_request_globals (void )
17101735{
1711- clear_last_error ();
1736+ clear_last_error (true );
17121737 if (PG (php_sys_temp_dir )) {
17131738 efree (PG (php_sys_temp_dir ));
17141739 PG (php_sys_temp_dir ) = NULL ;
@@ -2039,7 +2064,7 @@ void php_request_shutdown(void *dummy)
20392064 /* 16. Free Willy (here be crashes) */
20402065 zend_arena_destroy (CG (arena ));
20412066 zend_interned_strings_deactivate ();
2042- clear_last_error ();
2067+ clear_last_error (true );
20432068 zend_try {
20442069 shutdown_memory_manager (CG (unclean_shutdown ) || !report_memleaks , 0 );
20452070 } zend_end_try ();
@@ -2456,7 +2481,7 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
24562481 module_startup = false;
24572482
24582483 /* Don't leak errors from startup into the per-request phase. */
2459- clear_last_error ();
2484+ clear_last_error (true );
24602485 shutdown_memory_manager (1 , 0 );
24612486 virtual_cwd_activate ();
24622487
@@ -2519,7 +2544,7 @@ void php_module_shutdown(void)
25192544
25202545 /* close down the ini config */
25212546 php_shutdown_config ();
2522- clear_last_error ();
2547+ clear_last_error (true );
25232548
25242549#ifndef ZTS
25252550 zend_ini_shutdown ();
0 commit comments