diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index fe14dacd81..d53d3732be 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -3775,11 +3775,9 @@ function _drupal_shutdown_function() { // was in the normal context of execution. chdir(DRUPAL_ROOT); - reset($callbacks); try { - while ($callback = current($callbacks)) { + foreach ($callbacks as &$callback) { call_user_func_array($callback['callback'], $callback['arguments']); - next($callbacks); } } catch (Exception $exception) { diff --git a/includes/menu.inc b/includes/menu.inc index f5537ffc3e..ca37ba509d 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -576,7 +576,6 @@ function _menu_load_objects(&$item, &$map) { // 'load arguments' in the hook_menu() entry, but they need // some processing. In this case the $function is the key to the // load_function array, and the value is the list of arguments. - reset($function); $args = current($function); $function = key($function); $load_functions[$index] = $function; @@ -2404,8 +2403,8 @@ function menu_set_active_trail($new_trail = NULL) { // a stripped down menu tree containing the active trail only, in case // the given menu has not been built in this request yet. $tree = menu_tree_page_data($preferred_link['menu_name'], NULL, TRUE); - reset($tree); $curr = current($tree); + next($tree); } // There is no link for the current path. else { @@ -2434,7 +2433,6 @@ function menu_set_active_trail($new_trail = NULL) { } } $tree = $curr['below'] ? $curr['below'] : array(); - reset($tree); } $curr = current($tree); next($tree); diff --git a/includes/module.inc b/includes/module.inc index f8e229dd78..4c2b3fbeeb 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -404,7 +404,11 @@ function module_enable($module_list, $enable_dependencies = TRUE) { // Create an associative array with weights as values. $module_list = array_flip(array_values($module_list)); + // The array is iterated over manually (instead of using a foreach) because + // modules may be added to the list within the loop and we need to process + // them. while ($module = key($module_list)) { + next($module_list); if (!isset($module_data[$module])) { // This module is not found in the filesystem, abort. return FALSE; @@ -423,8 +427,6 @@ function module_enable($module_list, $enable_dependencies = TRUE) { $module_list[$dependency] = 0; } } - - next($module_list); } if (!$module_list) { @@ -542,7 +544,11 @@ function module_disable($module_list, $disable_dependents = TRUE) { $module_list = array_flip(array_values($module_list)); $profile = drupal_get_profile(); + // The array is iterated over manually (instead of using a foreach) because + // modules may be added to the list within the loop and we need to process + // them. while ($module = key($module_list)) { + next($module_list); if (!isset($module_data[$module]) || !$module_data[$module]->status) { // This module doesn't exist or is already disabled, skip it. unset($module_list[$module]); @@ -557,8 +563,6 @@ function module_disable($module_list, $disable_dependents = TRUE) { $module_list[$dependent] = 0; } } - - next($module_list); } // Sort the module list by pre-calculated weights. diff --git a/modules/book/book.module b/modules/book/book.module index 12580ef5b6..32047f93f5 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -768,6 +768,7 @@ function book_prev($book_link) { return NULL; } $flat = book_get_flat_menu($book_link); + reset($flat); $curr = NULL; do { $prev = $curr; @@ -807,6 +808,7 @@ function book_prev($book_link) { */ function book_next($book_link) { $flat = book_get_flat_menu($book_link); + reset($flat); do { $key = key($flat); next($flat); diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 3124ffe82a..3715ff1be2 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1128,7 +1128,11 @@ class DrupalWebTestCase extends DrupalTestCase { } } } - usort($files, array($this, 'drupalCompareFiles')); + $d_compare='drupalCompareFiles'; + // For php 7.2 replace return array() with function lambda. + usort($files, function($this, $d_compare) { + return array($this, $d_compare); + }); return $files; }