php.net |  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
Votes:1
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
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:
29 + 14 = ?
Subscribe to this entry?

 
 [2018-04-23 03:04 UTC] bonnevillessei67 at hotmail dot com
Description:
------------
A strong suggestion to change the wording on this page.
http://php.net/manual/en/class.arrayiterator.php

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.
https://stackoverflow.com/questions/10502719/difference-between-arrayiterator-arrayobject-and-array-in-php



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-23 03:25 UTC] requinix@php.net
-Package: Documentation problem +Package: SPL related
 [2018-04-23 03:25 UTC] requinix@php.net
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. https://3v4l.org/KFStB

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: Thu Apr 25 23:01:29 2024 UTC