|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38478 reset() does not work as expected on Iterator implementations
Submitted: 2006-08-17 08:20 UTC Modified: 2006-10-31 23:32 UTC
From: Assigned: helly (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.2.0 OS: *
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:
New email:
PHP Version: OS:


 [2006-08-17 08:20 UTC]
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:

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) {
      string(3) "one"
      string(3) "two"
      string(5) "three"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-31 23:32 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

In PHP objects are also arrays of their properties and reset and friends only work on real arrays. Thus the result is correct.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC