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
 [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

Pull Requests

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: Fri Nov 22 01:01:30 2024 UTC