php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64403 missing iterator object with RecursiveIteratorIterator::getInnerIterator
Submitted: 2013-03-11 11:05 UTC Modified: 2013-03-11 12:46 UTC
From: namarpi at yahoo dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.4.12 OS: Windows XP
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: namarpi at yahoo dot com
New email:
PHP Version: OS:

 

 [2013-03-11 11:05 UTC] namarpi at yahoo dot com
Description:
------------
After using RecursiveIteratorIterator::getInnerIterator method in a loop, there is a missing RecursiveArrayIterator object in the result. 	

For comparison, RecursiveIteratorIterator::getSubIterator method returns the expected result also.

Test script:
---------------
$array = array (
    'question' => 'text',
    'items'    => array (
            '0' => array ( 'phrase' => 'text text', ),
            '1' => array ( 'phrase' => 'text text text', ),
    ),
);

$array_object = new ArrayObject( $array, 0, "RecursiveArrayIterator"  );
$iterator     = new RecursiveIteratorIterator( $array_object->getIterator() );

foreach( $iterator as $key => $value ) {
    print_r( $iterator->getInnerIterator() ); // missing RecursiveArrayIterator Object of "items"
}

while( $iterator->valid() ) {
    print_r( $iterator->getInnerIterator() ); // missing RecursiveArrayIterator Object of "items"
    $iterator->next();
}

foreach( $iterator as $key => $value ) {
    for( $i = 0; $i <= $iterator->getDepth(); $i++ ) {
        print_r( $iterator->getSubIterator($i) ); // correct
    }
}

Expected result:
----------------
The getInnerIterator method should return this object too:
[11-Mar-2013 10:37:04 UTC] RecursiveArrayIterator Object
(
    [storage:ArrayIterator:private] => Array
        (
            [0] => Array
                (
                    [phrase] => text text
                )
            [1] => Array
                (
                    [phrase] => text text text
                )
        )
)

Actual result:
--------------
Missing the Expected result.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-11 12:06 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2013-03-11 12:06 UTC] salathe@php.net
The RecursiveIteratorIterator is only iterating over the "leaf nodes". It looks 
like you want to use the RecursiveIteratorIterator::SELF_FIRST or 
RecursiveIteratorIterator::CHILD_FIRST iteration mode (default is 
RecursiveIteratorIterator::LEAVES_ONLY).
 [2013-03-11 12:46 UTC] namarpi at yahoo dot com
I badly missed the point. Thank you for the quick hint.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 11:01:32 2025 UTC