php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46818 ParentIterator Initializing
Submitted: 2008-12-10 05:22 UTC Modified: 2008-12-10 23:08 UTC
From: kosugi at kips dot gr dot jp Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.2.8 OS: Linux 2.6.18
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: kosugi at kips dot gr dot jp
New email:
PHP Version: OS:

 

 [2008-12-10 05:22 UTC] kosugi at kips dot gr dot jp
Description:
------------
ParentIterator that only shows those elements which have children.
But I can't get the expected result without rewind() in starting an iteration.

Reproduce code:
---------------
$target = array(
    'foo' => array(1,2,3),
    'bar' => array(11,12,13),
    'baz'
);
$rai = new RecursiveArrayIterator($target);
$pi = new ParentIterator($rai);
//$pi->rewind();
while ($pi->valid()) {
    var_dump($pi->current());
    $pi->next();
}

Expected result:
----------------
array(5) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}
array(5) {
  [0]=>
  int(11)
  [1]=>
  int(12)
  [2]=>
  int(13)
}

Actual result:
--------------
// no output

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-10 05:36 UTC] kosugi at kips dot gr dot jp
It is a gross misunderstanding.
 [2008-12-10 23:08 UTC] kosugi at kips dot gr dot jp
I got expected result with "this->rewind()" in constructor.

class pi extends ParentIterator
{
    public function __construct($iterator)
    {
        parent::__construct($iterator);
        $this->rewind();
    }
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 05:00:01 2025 UTC