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

Add a Patch

Pull Requests

Add a Pull Request

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