each() has been deprecated in PHP 7.2 and is scheduled for removal in PHP 8.0.

Comments

drewklein created an issue. See original summary.

drewklein’s picture

StatusFileSize
new9.05 KB
drewklein’s picture

Status: Active » Patch (to be ported)
drewklein’s picture

Status: Patch (to be ported) » Needs review
drewklein’s picture

dawehner’s picture

Thank you for trying to proactive with future changes of PHP!

  1. +++ b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
    @@ -201,30 +201,31 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) {
    +        foreach ($matches as $y) {
    +          if (!$found_empty && empty($this->in_seq[$y])) {
    ...
    -            break;
    +            $found_empty = TRUE;
    

    It would be nice if you could try to minimize the amount of changes. As far as I know break; also works for foreach. You could reduce the diff here a bit, by really just replacing while with a foreach, see https://3v4l.org/b7EkO. list() is totally usable in a foreach loop as well.

  2. +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
    @@ -94,7 +94,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
    -      while (list($module) = each($module_list)) {
    +      foreach ($module_list as $module => $_) {
    
    @@ -331,7 +331,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
    -      while (list($module) = each($module_list)) {
    +      foreach ($module_list as $module => $_) {
    
    +++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
    @@ -121,7 +121,7 @@ public function install(array $theme_list, $install_dependencies = TRUE) {
    -      while (list($theme) = each($theme_list)) {
    +      foreach ($theme_list as $theme => $_) {
    

    What about using array_keys() here?

Anonymous’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

yeah let's mark this one as duplicate of the other.

tstoeckler’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
drewklein’s picture

That's fine about marking as a duplicate. But your comment about DiffEngine isn't correct. The way the code exists with each() the first loop iterates for a while using each() then stops. Then the second loop iterates for a while where the first one stopped. See https://3v4l.org/DZBS0