php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78274 iterator_to_array($array) should return the $array
Submitted: 2019-07-11 06:51 UTC Modified: 2019-07-11 12:09 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:2 of 3 (66.7%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Wes dot nospam at example dot org Assigned:
Status: Open Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
5 + 31 = ?
Subscribe to this entry?

 
 [2019-07-11 06:51 UTC] Wes dot nospam at example dot org
Description:
------------
Argument 1 passed to iterator_to_array() must implement interface Traversable, array given. 

Would be great to improve the behavior, possibly as follows:

iterator_to_array($array, TRUE); must return the array as is,

iterator_to_array($array, FALSE); must return array_values($array)

Thank you in advance




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-11 07:32 UTC] daverandom@php.net
Worth noting that the function is named *iterator*_to_array(), not *iterable*_to_array().

I'm not necessarily against extending the functionality like this, but in that case for consistency I would rather rename this function iterable_to_array() and retain iterator_to_array() as an alias.
 [2019-07-11 07:33 UTC] daverandom@php.net
-Type: Bug +Type: Feature/Change Request
 [2019-07-11 12:09 UTC] cmb@php.net
FWIW, there has been an RFC proposing iterable_to_array()[1],
which has been declined.

[1] <https://wiki.php.net/rfc/iterable_to_array-and-iterable_count>
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Nov 17 06:01:40 2019 UTC