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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC