1.2.288. Could Type With Iterable

Suggest using iterable typehint for arguments.

iterable represents both array and objects that implements Iterator interface. Both types are coerced, and usable here.

<?php

// $s may be both an array or an iterator
function foo($s) : int {
    $t = 0;
    foreach($s as $v) {
        $t += (int) $v;
    }

    return $t;
}

?>

See also Iterables.

1.2.288.1. Connex PHP features

1.2.288.1.1. Suggestions

  • Add the iterable type

1.2.288.1.2. Specs

Short name

Functions/CouldTypeWithIterable

Rulesets

All, Changed Behavior

Exakat since

1.9.9

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud