On Tue, Jul 3, 2018 at 10:48 PM, Michael Moravec <php....@majkl578.cz>
wrote:

> Hello internals,
>
> The RFC for adding iterable_to_array() and iterable_count() is now open for
> voting:
>
> https://wiki.php.net/rfc/iterable_to_array-and-iterable_count
>
> You can vote for each function separately.
>
> Voting will close on 2018-07-17 12:00 UTC.


I voted against both functions. Jordi already explained why
iterable_count() is questionable, so let me add a comment regarding
iterable_to_array().

Essentially my gripe is that I'm not convinced of the usefulness of this
function and am concerned that it might be encouraging bad practices. In
particular:

 * As the RFC already mentions, iterable_to_array() can be replaced by a
simple and in my eyes very clear one-liner. This pattern would have to be
extraordinarily common to justify adding a function for it.
 * The operation iterable_to_array() *should* be rare. Please do not accept
iterable arguments if you are not just iterating over them. If your
operation requires conversion to array, then directly accept an array,
otherwise you are making false promises. If you want to use an array
function on an iterable -- don't. Reimplement the function to work with
iterables or use a library that does.
 * The very close names of iterator_to_array() and iterable_to_array() are
somewhat confusing. For type declarations "iterable" and "Iterator" are
quite distinct due to different capitalization, but the functions are hard
to distinguish at a glance.

An additional issue is that iterable_to_array() preserves the behavior of
iterator_to_array() to preserve iterator keys by default, which is a big
footgun, especially in combination with generators. However, I also
understand that using a different default would be even worse, due to the
confusion with iterator_to_array().

Regards,
Nikita

Reply via email to