github-actions · GitHub

TimWolla

@TimWolla

Girgias

Girgias

@TimWolla

@TimWolla

Girgias

morrisonlevi

@TimWolla

@TimWolla TimWolla changed the title Make iterator_to_array() accept all iterables Make the iterator_*() family accept all iterables

Jun 21, 2022

@TimWolla TimWolla changed the title Make the iterator_*() family accept all iterables RFC: Make the iterator_*() family accept all iterables

Jun 21, 2022

@TimWolla

@TimWolla

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.

@TimWolla

iluuu1994

@TimWolla

@TimWolla

@mpyw mpyw mentioned this pull request

Jul 26, 2023

Closed

adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request

Aug 4, 2026

Read the original on github.com ↗