|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48272 function valid , next, current ..from subclass of FilterIterator return false
Submitted: 2009-05-14 03:39 UTC Modified: 2009-05-22 01:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: gma625 at msn dot com Assigned:
Status: No Feedback Package: SPL related
PHP Version: 5.2.6 OS: windows xp2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gma625 at msn dot com
New email:
PHP Version: OS:


 [2009-05-14 03:39 UTC] gma625 at msn dot com
When extends a class with FilterIterator, the valid ,current,key, next functions can't work, until you override your function with the following codes
public function valid() {

btw, my php works version is 5.2.6, I can't found this version in the select list , so I selected 5.2.9

Reproduce code:
error_reporting ( E_ALL | E_STRICT );
$array = array ('koala', 'kangaroo', 'wombat', 'wallaby', 'emu', 'NZ' => 'kiwi', 'kookaburra', 'platypus' );

class CullingIterator extends FilterIterator {
	public function __construct(Iterator $it) {
		parent::__construct ( $it );
	function accept() {
		$ittmp = $this->getInnerIterator ();
		if ($ittmp->current () == 'koala') {
			return false;
		return true;

$cull = new CullingIterator ( new ArrayIterator ( $array ) );

try {
	while ( $cull->valid () ) {
 		echo $cull->current ();
		$cull->next ();
} catch ( Exception $e ) {
	$e->getTraceAsString ();

Expected result:
print out the array result as following

Actual result:
print nothing, becuase when we call $cull->valid() will return false

additional information , I've also tracked this problem by the following code, 

$cull = new CullingIterator ( new ArrayIterator ( $array ) );

$it = $cull->getInnerIterator();

var_dump( $it->valid() );

and the result is bool(true), it's very strange to get this while we $cull->valid() it return false(true)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-14 03:44 UTC] gma625 at msn dot com
hello, I'm the reporter of this bug, I'm sorry for making a typing mistake below, I just get up to fix this typing mistake , But I don't know how to achieve , so I post a new comment here, sorry for the inconvience again . 


and the result is bool(true), it's very strange to get this while we
$cull->valid() it return false(true)


and the result is bool(true), it's very strange to get this while we
$cull->valid() it return bool(false)
 [2009-05-14 12:38 UTC]
Please try using this CVS snapshot:
For Windows:

 [2009-05-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2011-11-03 13:33 UTC] strauchdieb at gmx dot de
This bug still exists. See here for a newer bug report and a workaround:
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Aug 18 02:05:45 2022 UTC