|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-10-31 23:32 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 07:00:02 2025 UTC |
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" } */