|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-07 04:49 UTC] tobias382 at gmail dot com
[2010-08-07 05:03 UTC] colder@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: colder
[2013-09-12 22:40 UTC] levim@php.net
-Status: Assigned
+Status: Not a bug
-Assigned To: colder
+Assigned To: levim
[2013-09-12 22:40 UTC] levim@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
Description: ------------ Even when a FilterIterator subclass accepts all elements, it returns NULL for the first element in the original array. There are a few methods to correct this behavior, noted in the attached test script. Test script: --------------- <?php class FooIterator extends FilterIterator { /* // Forces this class to produce expected behavior below // (i.e. 1, 2, NULL instead of NULL, 2, NULL) public function __construct(Iterator $iterator) { parent::__construct($iterator); $iterator->rewind(); } */ // Should cause all elements to be accepted public function accept() { return true; } /* // Another way to force this class to produce expected behavior below public function current() { return $this->getInnerIterator()->current(); } */ } $array = array(1, 2); /* // What should happen in subsequent blocks $iterator1 = new ArrayIterator($array); var_dump($iterator1->current()); // int(1) $iterator1->next(); var_dump($iterator1->current()); // int(2) $iterator1->next(); var_dump($iterator1->current()); // NULL */ // The problem $iterator2 = new FooIterator(new ArrayIterator($array)); var_dump($iterator2->current()); // NULL <-- this should be int(1) $iterator2->next(); var_dump($iterator2->current()); // int(2) $iterator2->next(); var_dump($iterator2->current()); // NULL // Exhibits correct behavior with no changes to FooIterator $iterator3 = new FooIterator(new ArrayIterator($array)); $iterator3->rewind(); // This line shouldn't be needed, but is to force expected behavior var_dump($iterator3->current()); // int(1) $iterator3->next(); var_dump($iterator3->current()); // int(2) $iterator3->next(); var_dump($iterator3->current()); // NULL Expected result: ---------------- int(1) int(2) NULL int(1) int(2) NULL Actual result: -------------- NULL int(2) NULL int(1) int(2) NULL