|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-14 03:44 UTC] gma625 at msn dot com
[2009-05-14 12:38 UTC] jani@php.net
[2009-05-22 01:00 UTC] php-bugs at lists dot php dot net
[2011-11-03 13:33 UTC] strauchdieb at gmx dot de
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
Description: ------------ 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() { $this->getInnerIterator()->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 kangaroowombatwallabyemukiwikookaburraplatypus 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)