1.2.913. PHP 7.1 Scalar Typehints¶
A new scalar typehint was introduced : iterable.
It can’t be used before PHP 7.1, and will be confused with classes or interfaces.
<?php
function foo(iterable $iterable) {
foreach ($iterable as $value) {
echo $value.PHP_EOL;
}
}
foo(range(1,20));
// works with array
foo(new ArrayIterator([1, 2, 3]));
// works with an iterator
foo((function () { yield 1; })() );
// works with a generator
?>
See also iterable pseudo-type and The iterable Pseudo-Type.
1.2.913.1. Connex PHP features¶
1.2.913.1.1. Specs¶
Short name |
Php/PHP71scalartypehints |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70 |
Exakat since |
1.3.5 |
PHP Version |
With PHP 7.1 and more recent |
Severity |
Critical |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |