summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-11-13 11:20:57 (GMT)
committerNathaniel Catchpole2017-11-13 11:20:57 (GMT)
commit7206f5d9c939522756f78b94d5f662b50f53a667 (patch)
tree3ea47147f754ff77ca01d45f84b398fa0c11f068
parent9830ef98bc08eaf40be9e9001bb7a5e5cfd1b735 (diff)
Issue #2885309 by vaplas, drewklein, pk188, alexpott, Ayesh, arunkumark, andypost, klausi, xjm, mondrake: [PHP 7.2] each() function is deprecated
-rw-r--r--core/includes/bootstrap.inc2
-rw-r--r--core/lib/Drupal/Component/Diff/Engine/DiffEngine.php43
-rw-r--r--core/lib/Drupal/Core/Extension/ModuleInstaller.php8
-rw-r--r--core/lib/Drupal/Core/Extension/ThemeInstaller.php4
-rw-r--r--core/modules/book/src/BookOutline.php11
-rw-r--r--core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php6
-rw-r--r--core/modules/system/src/Form/ModulesListForm.php2
-rw-r--r--core/modules/system/src/Tests/Module/InstallUninstallTest.php2
-rw-r--r--core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php4
9 files changed, 42 insertions, 40 deletions
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 5a1cfbe..6c8ee5e 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -1003,7 +1003,7 @@ function _drupal_shutdown_function() {
chdir(DRUPAL_ROOT);
try {
- while (list($key, $callback) = each($callbacks)) {
+ foreach ($callbacks as &$callback) {
call_user_func_array($callback['callback'], $callback['arguments']);
}
}
diff --git a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
index b56aa99..e7c2941 100644
--- a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
+++ b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
@@ -201,28 +201,29 @@ class DiffEngine {
continue;
}
$matches = $ymatches[$line];
- reset($matches);
- while (list ($junk, $y) = each($matches)) {
- if (empty($this->in_seq[$y])) {
- $k = $this->_lcs_pos($y);
- $this::USE_ASSERTS && assert($k > 0);
- $ymids[$k] = $ymids[$k - 1];
- break;
- }
- }
- while (list ($junk, $y) = each($matches)) {
- if ($y > $this->seq[$k - 1]) {
- $this::USE_ASSERTS && assert($y < $this->seq[$k]);
- // Optimization: this is a common case:
- // next match is just replacing previous match.
- $this->in_seq[$this->seq[$k]] = FALSE;
- $this->seq[$k] = $y;
- $this->in_seq[$y] = 1;
+ foreach ($matches as $y) {
+ if (!isset($found_empty)) {
+ if (empty($this->in_seq[$y])) {
+ $k = $this->_lcs_pos($y);
+ $this::USE_ASSERTS && assert($k > 0);
+ $ymids[$k] = $ymids[$k - 1];
+ $found_empty = TRUE;
+ }
}
- elseif (empty($this->in_seq[$y])) {
- $k = $this->_lcs_pos($y);
- $this::USE_ASSERTS && assert($k > 0);
- $ymids[$k] = $ymids[$k - 1];
+ else {
+ if ($y > $this->seq[$k - 1]) {
+ $this::USE_ASSERTS && assert($y < $this->seq[$k]);
+ // Optimization: this is a common case:
+ // next match is just replacing previous match.
+ $this->in_seq[$this->seq[$k]] = FALSE;
+ $this->seq[$k] = $y;
+ $this->in_seq[$y] = 1;
+ }
+ elseif (empty($this->in_seq[$y])) {
+ $k = $this->_lcs_pos($y);
+ $this::USE_ASSERTS && assert($k > 0);
+ $ymids[$k] = $ymids[$k - 1];
+ }
}
}
}
diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
index 8792498..ec1ca5c 100644
--- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -93,8 +93,8 @@ class ModuleInstaller implements ModuleInstallerInterface {
}
// Add dependencies to the list. The new modules will be processed as
- // the while loop continues.
- while (list($module) = each($module_list)) {
+ // the foreach loop continues.
+ foreach ($module_list as $module => $value) {
foreach (array_keys($module_data[$module]->requires) as $dependency) {
if (!isset($module_data[$dependency])) {
// The dependency does not exist.
@@ -340,9 +340,9 @@ class ModuleInstaller implements ModuleInstallerInterface {
if ($uninstall_dependents) {
// Add dependent modules to the list. The new modules will be processed as
- // the while loop continues.
+ // the foreach loop continues.
$profile = drupal_get_profile();
- while (list($module) = each($module_list)) {
+ foreach ($module_list as $module => $value) {
foreach (array_keys($module_data[$module]->required_by) as $dependent) {
if (!isset($module_data[$dependent])) {
// The dependent module does not exist.
diff --git a/core/lib/Drupal/Core/Extension/ThemeInstaller.php b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
index 5472d3e..43a5469 100644
--- a/core/lib/Drupal/Core/Extension/ThemeInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
@@ -121,9 +121,9 @@ class ThemeInstaller implements ThemeInstallerInterface {
return TRUE;
}
- while (list($theme) = each($theme_list)) {
+ foreach ($theme_list as $theme => $value) {
// Add dependencies to the list. The new themes will be processed as
- // the while loop continues.
+ // the parent foreach loop continues.
foreach (array_keys($theme_data[$theme]->requires) as $dependency) {
if (!isset($theme_data[$dependency])) {
// The dependency does not exist.
diff --git a/core/modules/book/src/BookOutline.php b/core/modules/book/src/BookOutline.php
index ec28d50..193c20f 100644
--- a/core/modules/book/src/BookOutline.php
+++ b/core/modules/book/src/BookOutline.php
@@ -39,12 +39,14 @@ class BookOutline {
if ($book_link['pid'] == 0) {
return NULL;
}
- // Assigning the array to $flat resets the array pointer for use with each().
$flat = $this->bookManager->bookTreeGetFlat($book_link);
+ reset($flat);
$curr = NULL;
do {
$prev = $curr;
- list($key, $curr) = each($flat);
+ $key = key($flat);
+ $curr = current($flat);
+ next($flat);
} while ($key && $key != $book_link['nid']);
if ($key == $book_link['nid']) {
@@ -78,10 +80,11 @@ class BookOutline {
* $book_link.
*/
public function nextLink(array $book_link) {
- // Assigning the array to $flat resets the array pointer for use with each().
$flat = $this->bookManager->bookTreeGetFlat($book_link);
+ reset($flat);
do {
- list($key,) = each($flat);
+ $key = key($flat);
+ next($flat);
} while ($key && $key != $book_link['nid']);
if ($key == $book_link['nid']) {
diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
index 9133a12..c5e3c2c 100644
--- a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
@@ -160,11 +160,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase {
foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
if (!in_array($type, $configurable) && isset($info['fixed'])) {
$negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
- $equal = count($info['fixed']) == count($negotiation);
- while ($equal && list($id) = each($negotiation)) {
- list(, $info_id) = each($info['fixed']);
- $equal = $info_id == $id;
- }
+ $equal = array_keys($negotiation) === array_values($info['fixed']);
$this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type]));
}
}
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 43969d4..3548263 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -388,7 +388,7 @@ class ModulesListForm extends FormBase {
}
// Add all dependencies to a list.
- while (list($module) = each($modules['install'])) {
+ foreach ($modules['install'] as $module => $value) {
foreach (array_keys($data[$module]->requires) as $dependency) {
if (!isset($modules['install'][$dependency]) && !$this->moduleHandler->moduleExists($dependency)) {
$modules['dependencies'][$module][$dependency] = $data[$dependency]->info['name'];
diff --git a/core/modules/system/src/Tests/Module/InstallUninstallTest.php b/core/modules/system/src/Tests/Module/InstallUninstallTest.php
index a78918b..e3c7af2 100644
--- a/core/modules/system/src/Tests/Module/InstallUninstallTest.php
+++ b/core/modules/system/src/Tests/Module/InstallUninstallTest.php
@@ -72,7 +72,7 @@ class InstallUninstallTest extends ModuleTestBase {
// Go through each module in the list and try to install and uninstall
// it with its dependencies.
- while (list($name, $module) = each($all_modules)) {
+ foreach ($all_modules as $name => $module) {
$was_installed_list = \Drupal::moduleHandler()->getModuleList();
// Start a list of modules that we expect to be installed this time.
diff --git a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
index 375766a..619b191 100644
--- a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -104,7 +104,9 @@ abstract class ViewsFormBase extends FormBase implements ViewsFormInterface {
// Retrieve the first form from the stack without changing the integer keys,
// as they're being used for the "2 of 3" progress indicator.
reset($view->stack);
- list($key, $top) = each($view->stack);
+ $key = key($view->stack);
+ $top = current($view->stack);
+ next($view->stack);
unset($view->stack[$key]);
if (array_shift($top) != $identifier) {