|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76250 Better Documentation Description - ArrayIterator Class
Submitted: 2018-04-23 03:04 UTC Modified: 2018-04-23 03:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: bonnevillessei67 at hotmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: 7.0.29 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bonnevillessei67 at hotmail dot com
New email:
PHP Version: OS:


 [2018-04-23 03:04 UTC] bonnevillessei67 at hotmail dot com
A strong suggestion to change the wording on this page.

This statement caused me to pull my hair out for three days to understand what is being said.

"When you want to iterate over the same array multiple times you need to instantiate ArrayObject and let it create ArrayIterator instances that refer to it either by using foreach or by calling its getIterator() method manually."

This is a much better explanation of how ArrayObject and ArrayIterator work together.

"ArrayObject cannot be iterated when you use it in foreach it creates an ArrayIterator object internally"

Scroll down to "Comparing ArrayObject vs ArrayIterator" in this Stackoverflow link for context.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-23 03:25 UTC]
-Package: Documentation problem +Package: SPL related
 [2018-04-23 03:25 UTC]
I don't understand what the original description is trying to say, but your version sounds downright incorrect.

ArrayIterator can be iterated over because it is an iterator, meaning it has implemented the necessary logic (Iterator interface) to do so.
ArrayObject can be iterated over because it passes the work off (IteratorAggregate interface) to an ArrayIterator instance, and the process is entirely transparent.
Both will work fine in a foreach - even multiple times in a row.

If anything that part should be removed entirely. I can't be sure but I believe it's at least 10 years old so it could very well just not be true anymore.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 12:01:28 2024 UTC