|  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: 2021-11-08 11:57 UTC
Avg. Score:3.5 ± 1.7
Reproduced:3 of 4 (75.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Wes dot nospam at example dot org Assigned:
Status: Open Package: SPL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: Wes dot nospam at example dot org
New email:
PHP Version: OS:


 [2019-07-11 06:51 UTC] Wes dot nospam at example dot org
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-11 07:32 UTC]
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]
-Type: Bug +Type: Feature/Change Request
 [2019-07-11 12:09 UTC]
FWIW, there has been an RFC proposing iterable_to_array()[1],
which has been declined.

[1] <>
 [2021-11-08 11:57 UTC]
-Package: *General Issues +Package: SPL related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 03:01:29 2024 UTC