php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64528 ParentIterator doc refers to RecursiveIteratorIterator (wrong)
Submitted: 2013-03-26 21:38 UTC Modified: 2013-03-26 23:17 UTC
From: jon at langevin dot me Assigned: salathe (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.23 OS:
Private report: No CVE-ID: None
 [2013-03-26 21:38 UTC] jon at langevin dot me
Description:
------------
ParentIterator docs say that it can be used to iterate a 
RecursiveIteratorIterator, but that is incorrect, as ParentIterator is expecting 
RecursiveIterator or a child class.

While it would make sense for ParentIterator to accept RecursiveIteratorIterator, 
that's not the case currently, so anyone trying to follow the documentation will 
get an error.
The class signature for ParentIterator correctly shows that it accepts 
RecursiveIterator, but the doc does not support that.

There is a comment on the doc page from a user showing code, using 
RecursiveIteratorIterator as an argument to ParentIterator (apparently it was 
successful for him?), which suggests this may actually work in a different 
version of PHP.

Documentation error can be seen here: 
http://www.php.net/manual/en/class.parentiterator.php

Test script:
---------------
new \ParentIterator(new \RecursiveIteratorIterator(new \RecursiveIterator, \RecursiveIteratorIterator::CHILD_FIRST));


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-26 23:17 UTC] salathe@php.net
The description could be worded better, but your interpretation is not what is being said. The 
page does not say that the ParentIterator can be used to iterate a RecursiveIteratorIterator, 
rather (in a slightly unclear, more concise way) that the effect of using ParentIterator when 
provided to a RecursiveIteratorIterator is such that only elements with children are accepted. 
Some background knowledge is required to easily make sense of the description, so I can see where 
you stumbled.

The user contributed code to which you refer is also incorrect. RecursiveIteratorIterator does 
not implement the RecursiveIterator interface, so a (catchable) fatal error is raised.  The code 
should instead wrap the RecursiveDirectoryIterator inside a ParentIterator and then provide that 
to the RecursiveIteratorIterator.

Marking this as "not a bug" since the existing text is correct. However, I will look at editing 
both the description and the user contributed code.
 [2013-03-26 23:17 UTC] salathe@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: salathe
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 02:01:24 2020 UTC