1.2.1196. This Could Be Iterable¶
An argument that is both array and traversable <https://www.php.net/`traversable>`_ may be typed iterable. Iterable is a more generic type than array, and allows the usage of iterators too.
<?php
// parameter and return type might be iterable
function foo($a) {
foreach($a as $b) {
// do something
}
return $a;
}
class x {
private $b;
function foo() {
foreach($this->b as $c) {
// do something
}
}
}
?>
See also iterable.
1.2.1196.1. Connex PHP features¶
1.2.1196.1.1. Suggestions¶
Add the iterable typehint
1.2.1196.1.2. Specs¶
Short name |
Classes/CouldBeIterable |
Rulesets |
|
Exakat since |
2.3.3 |
PHP Version |
With PHP 7.1 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |