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
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: bonnevillessei67 at hotmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 06:01:29 2024 UTC