1.2.1427. While(List() = Each())

This code structure is quite old : it should be replace by the more modern and efficient foreach.

This structure is deprecated since PHP 7.2. It may disappear in the future.

<?php

    while(list($key, $value) = each($array)) {
        doSomethingWith($key) and $value();
    }

    foreach($array as $key => $value) {
        doSomethingWith($key) and $value();
    }
?>

See also PHP RFC: Deprecations for PHP 7.2 : Each().

1.2.1427.1. Suggestions

  • Change this loop with foreach

  • Change this loop with an array_* functions with a callback

1.2.1427.2. Specs

Short name

Structures/WhileListEach

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, Performances, Suggestions

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

while

Examples

OpenEMR, Dolphin

Available in

Entreprise Edition, Community Edition, Exakat Cloud