|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44793 ArrayObject does not report as Iterator
Submitted: 2008-04-21 12:52 UTC Modified: 2008-05-25 11:47 UTC
Avg. Score:4.6 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:2 (40.0%)
From: matthew at zend dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5+ OS: *
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: matthew at zend dot com
New email:
PHP Version: OS:


 [2008-04-21 12:52 UTC] matthew at zend dot com
ArrayObject extends ArrayAccess, which implements ArrayIterator and in turn Iterator. However, when checking to see if a concrete instance of ArrayObject implements Iterator, the return is false.

Reproduce code:
$o = new ArrayObject(array());
if ($o instanceof Iterator) {
    echo "Instance of Iterator";
} else {
    echo "Failed";

Expected result:
Instance of Iterator

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-21 15:51 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

class ArrayObject implements IteratorAggregate, Traversable, ArrayAccess, Serializable, Countable.

Traversable is not the same as Iterator: Traversable allows an object to be magically iterated by, i.e foreach, while Iterator explicitly provides userland iteration interface through next/valid/current/key/rewind.
 [2008-04-21 16:03 UTC] matthew at zend dot com
This is a bug in SPL, which is bundled in PHP core; additionally, it exposes a potential issue with how inheritence is resolved in the language. Please re-open.
 [2008-04-21 16:07 UTC]
 [2008-04-21 16:12 UTC]
Actually, ArrayAccess does not implment ArrayIterator, but vice versa. ArrayObject therefor does not implement Iterator.
 [2008-05-25 11:47 UTC]
For you rand everybodies education, there are two very useful commands as shown below. The second shows that ArrayAccess does not implement any Interface at all. The first shows that ArrayObject and ArrayIterator are on the same level. Doing 'php --rc ArrayIterator' and 'php --rc ArrayObject' you will find that the former implement Iterator while as the second implements IteratorAggregate which in turn does not inherit Iterator.

[marcus@zaphod php-cvs]$ php ext/spl/examples/class_tree.php ArrayAccess
make: `sapi/cli/php' is up to date.
| \-RecursiveArrayIterator (RecursiveIterator)
|   \-SubClasses
|-CachingIterator (ArrayAccess, Countable)
| \-RecursiveCachingIterator (RecursiveIterator)
| |-SplQueue
| \-SplStack
[marcus@zaphod php-cvs]$ php --rc ArrayAccess
make: `sapi/cli/php' is up to date.
Interface [ <internal> interface ArrayAccess ] {

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 27 03:01:25 2019 UTC