#48272 [Opn->Fbk]: function valid , next, current ..from subclass of FilterIterator return false
| From: | jani@php.net | Date: | Thu, 14 May 2009 12:38:20 +0000 |
| Subject: | #48272 [Opn->Fbk]: function valid , next, current ..from subclass of FilterIterator return false | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137304@lists.php.net to get a copy of this message | ||
ID: 48272
Updated by: jani@php.net
Reported By: gma625 at msn dot com
-Status: Open
+Status: Feedback
Bug Type: SPL related
Operating System: windows xp2
-PHP Version: 5.2.9
+PHP Version: 5.2.6
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2009-05-14 03:44:17] 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 .
mistake:
and the result is bool(true), it's very strange to get this while we
$cull->valid() it return false(true)
fix:
and the result is bool(true), it's very strange to get this while we
$cull->valid() it return bool(false)
------------------------------------------------------------------------
[2009-05-14 03:39:08] gma625 at msn dot com
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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48272&edit=1