TimWolla
changed the title
Make
Make the iterator_to_array() accept all iterablesiterator_*() family accept all iterables
TimWolla
changed the title
Make the
RFC: Make the iterator_*() family accept all iterablesiterator_*() family accept all iterables
Merged
While calling this function on an array either is a no-op or is equivalent to
`\array_values()` if the `$preserve_keys` flag is `false`, it is also
unnecessarily limiting for it to reject proper arrays.
By allowing it to take the full `iterable` family, it is more easily possible
to write a function that operates on an arbitrary `iterable` and internally
uses array-specific functionality, such as `array_filter` or `array_map`:
function test(iterable $foo) {
$foo = iterator_to_array($foo);
return array_map(strlen(...), $foo);
}
With this change it behaves similarly to `Array.from()` in JavaScript.
mpyw
mentioned this pull request
Closed
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request
Aug 4, 2026