#38478 [NEW]: reset() does not work as expected on Iterator implementations

From: Date: Thu, 17 Aug 2006 08:20:07 +0000
Subject: #38478 [NEW]: reset() does not work as expected on Iterator implementations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100882@lists.php.net to get a copy of this message
From: toby@php.net Operating system: Gentoo PHP version: 5.2.0RC1 PHP Bug Type: SPL related Bug description: reset() does not work as expected on Iterator implementations Description: ------------ The Iterator interface (SPL) defines a method rewind(). When implementing e.g. ArrayIterator to allow array access to an object, one would expect that reset($object) would use the rewind method. This does not happen, but the first property is returned. Reproduce code: --------------- <?php class testArray implements Iterator { protected $prop = array( 1 => 'one', 2 => 'two', 3 => 'three', ); public function rewind() { return reset( $this->prop ); } public function key() { return key( $this->prop ); } public function current() { return current( $this->prop ); } public function next() { return next( $this->prop ); } public function valid() { return ( current( $this->prop ) !== false ); } } $array = new testArray(); Expected result: ---------------- // Expected: string(3) "one" var_dump( $array->rewind() ); // Expected: string(3) "one" var_dump( reset( $array ) ); Actual result: -------------- // As expected: string(3) "one" var_dump( $array->rewind() ); // Expected: string(3) "one" var_dump( reset( $array ) ); /* Got: array(3) { [1]=> string(3) "one" [2]=> string(3) "two" [3]=> string(5) "three" } */ -- Edit bug report at http://bugs.php.net/?id=38478&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38478&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38478&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38478&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38478&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38478&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38478&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38478&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38478&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38478&r=support Expected behavior: http://bugs.php.net/fix.php?id=38478&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38478&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38478&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38478&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38478&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38478&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38478&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38478&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38478&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38478&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38478&r=mysqlcfg

« previous php.bugs (#100882) next »