| asgrim | Yes | 2022-07-06 06:30 |
| bwoebi | Yes | 2022-07-07 23:28 |
| colinodell | Yes | 2022-07-05 15:18 |
| crell | Yes | 2022-07-05 19:46 |
| jwage | Yes | 2022-07-15 22:01 |
| kalle | Yes | 2022-07-05 15:08 |
| kguest | Yes | 2022-07-11 16:06 |
| levim | No | 2022-07-05 16:52 |
| marandall | Yes | 2022-07-08 11:44 |
| nicolasgrekas | Yes | 2022-07-14 06:30 |
| ocramius | Yes | 2022-07-05 15:05 |
| reywob | Yes | 2022-07-13 13:42 |
| salathe | No | 2022-07-05 14:58 |
| santiagolizardo | Yes | 2022-07-09 19:49 |
| sergey | Yes | 2022-07-06 06:21 |
| svpernova09 | Yes | 2022-07-12 16:13 |
| timwolla | Yes | 2022-07-05 14:30 |
| trowski | Yes | 2022-07-16 15:32 |
| weierophinney | Yes | 2022-07-11 20:56 |
| asgrim | Yes | 2022-07-06 06:30 |
| bmajdak | Yes | 2022-07-05 17:06 |
| bwoebi | Yes | 2022-07-07 23:28 |
| colinodell | Yes | 2022-07-05 15:18 |
| crell | Yes | 2022-07-05 19:47 |
| jwage | Yes | 2022-07-15 22:01 |
| kalle | Yes | 2022-07-05 15:08 |
| kguest | Yes | 2022-07-11 16:06 |
| levim | No | 2022-07-05 16:52 |
| nicolasgrekas | Yes | 2022-07-14 06:30 |
| ocramius | Yes | 2022-07-05 15:05 |
| reywob | Yes | 2022-07-13 13:42 |
| salathe | No | 2022-07-05 14:58 |
| santiagolizardo | Yes | 2022-07-09 19:49 |
| sergey | Yes | 2022-07-06 06:22 |
| svpernova09 | Yes | 2022-07-12 16:13 |
| timwolla | Yes | 2022-07-05 14:30 |
| trowski | Yes | 2022-07-16 15:32 |
| weierophinney | Yes | 2022-07-11 20:56 |
Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC
PHP's iterator_*() family currently only accept \Traversables (i.e. they reject plain arrays). This is unnecessarily limiting.
Specifically this concerns the iterator_to_array() and iterator_count() functions. While each of them has an array-specific counterpart, the fact that one needs to choose either the array-specific variant or the everything-but-array variant makes writing code the deals with arbitrary iterables unnecessarily verbose.
As an example: Allowing iterator_to_array() to take an array, makes it much easier to write functions accepting an iterable and processing it using array_map() et al:
function before(iterable $foo) {
if (!is_array($foo)) {
$foo = iterator_to_array($foo);
}
return array_map(strlen(...), $foo);
}
function after(iterable $foo) {
$foo = iterator_to_array($foo);
return array_map(strlen(...), $foo);
}
The $iterator parameter of iterator_to_array() and iterator_count() should be widened from \Traversable to iterable (i.e. to \Traversable|array).
Specifically if this RFC is accepted the following shall hold:
iterator_to_array($array, true) == $array
iterator_to_array($array, false) == array_values($array)
iterator_count($array) == count($array)
This function is not part of this proposal, because it is non-obvious how to define the behavior for arrays, given that it does not pass the Iterator to the callback by default.
None, this is a purely type widening change.
next PHP 8.x
none
none
none
none
none
none
Anything that isn't iterator_to_array() or iterator_count().
none
Each vote requires a 2/3 majority.
Voting opened 2022-07-05 14:30 UTC and closes on 2022-07-19 14:45 UTC.
Vote: iterator_to_array: Change the type of iterator_to_array()’s $iterator parameter from \Traversable to iterable? — Yes: 17 · No: 2 (closed)
Vote: iterator_count: Change the type of iterator_count()’s $iterator parameter from \Traversable to iterable? — Yes: 17 · No: 2 (closed)
https://github.com/php/php-src/pull/8819
https://github.com/php/php-src/commit/7ae7df5b4601f3f0ce45a27324fb9c6ebcbfc9ed
iterable_* prefix: https://externals.io/rfc/iterable_to_array-and-iterable_countiterable_to_array(): https://stackoverflow.com/q/44587973/782822none