Bug #64428 [Opn]: SPL RecursiveIteratorIterator::getChildren Uncaught exception

From: Date: Fri, 15 Mar 2013 11:15:41 +0000
Subject: Bug #64428 [Opn]: SPL RecursiveIteratorIterator::getChildren Uncaught exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-177802@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64428&edit=1

 ID:                 64428
 User updated by:    namarpi at yahoo dot com
 Reported by:        namarpi at yahoo dot com
 Summary:            SPL RecursiveIteratorIterator::getChildren Uncaught
                     exception
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   Windows XP
 PHP Version:        5.4.13
 Block user comment: N
 Private report:     N

 New Comment:

Sorry, correctly this is about RecursiveArrayIterator::getChildren, and a more proper

Test script here:
---------------------------

function example() {
    $array = array (
            'a' => array(
                    'a_1' => 'a 1 text',
            ),
    );

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

    foreach( $iterator as $key => $current ) {
var_dump( $iterator->getInnerIterator() );

        //if( $key == 'a' ) {
var_dump( get_class($iterator->getInnerIterator() ));
var_dump( $iterator->getInnerIterator()->getChildren() );
        //}
    }
}

example();


Previous Comments:
------------------------------------------------------------------------
[2013-03-15 09:40:23] namarpi at yahoo dot com

Description:
------------
Recently I am working with SPL Iterators, and got an uncaught exception with the Test script.



Test script:
---------------
function example() {
    $array = array (
            'a' => array(
                    'a_1' => 'a 1 text',
            ),
    );

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

    foreach( $iterator as $key => $current ) {
var_dump( $iterator->getChildren );
var_dump( $iterator->getInnerIterator() );
        //if( $key == 'a' ) {
var_dump( $iterator->getInnerIterator()->getChildren() );
        //}
    }
}

example();

Expected result:
----------------
Smooth iteration through the leaves.

Actual result:
--------------
[15-Mar-2013 09:29:55 UTC] PHP Fatal error:  Uncaught exception 'InvalidArgumentException'
with message 'Passed variable is not an array or object, using empty array instead' in
[...]
Stack trace:
#0 [internal function]: ArrayIterator->__construct('a 1 text', 67108864)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64428&edit=1


Thread (6 messages)

« previous php.bugs (#177802) next »