some questions about the usage of Iterator function
<p>Code is from:<a href="http://php.net/manual/en/class.iterator.php(Example" rel="nofollow">http://php.net/manual/en/class.iterator.php(Example</a> #1 Basic usage)</p>

<pre><code>&lt;?php
class myIterator implements Iterator {
    private $position = 0;
    private $array = array(
        "firstelement",
        "secondelement",
        "lastelement",
    );  

    public function __construct() {
        $this-&gt;position = 0;
    }

    function rewind() {
        var_dump(__METHOD__);
        $this-&gt;position = 0;
    }

    function current() {
        var_dump(__METHOD__);
        return $this-&gt;array[$this-&gt;position];
    }

    function key() {
        var_dump(__METHOD__);
        return $this-&gt;position;
    }

    function next() {
        var_dump(__METHOD__);
        ++$this-&gt;position;
    }

    function valid() {
        var_dump(__METHOD__);
        return isset($this-&gt;array[$this-&gt;position]);
    }
}

$it = new myIterator;

foreach($it as $key =&gt; $value) {
    var_dump($key, $value);
    echo "\n";
}
?&gt;
</code></pre>

<p>Output is:</p>

<pre><code>string 'myIterator::rewind' (length=18)

string 'myIterator::valid' (length=17)

string 'myIterator::current' (length=19)

string 'myIterator::key' (length=15)

int 0

string 'firstelement' (length=12)

string 'myIterator::next' (length=16)

string 'myIterator::valid' (length=17)

string 'myIterator::current' (length=19)

string 'myIterator::key' (length=15)

int 1

string 'secondelement' (length=13)

string 'myIterator::next' (length=16)

string 'myIterator::valid' (length=17)

string 'myIterator::current' (length=19)

string 'myIterator::key' (length=15)

int 2

string 'lastelement' (length=11)

string 'myIterator::next' (length=16)

string 'myIterator::valid' (length=17)
</code></pre>

<p>So we can see:
1st, the order of function(<code>var_dump(__METHOD__)</code>) output is:</p>

<pre><code>string 'myIterator::rewind' (length=18)
string 'myIterator::valid' (length=17)
string 'myIterator::current' (length=19)
string 'myIterator::key' (length=15)
</code></pre>

<p>2nd and 3rd, the order of function output is:
the order of function output is:</p>

<pre><code>string 'myIterator::next' (length=16)
string 'myIterator::valid' (length=17)
string 'myIterator::current' (length=19)
string 'myIterator::key' (length=15)
</code></pre>

<p>4rd, the order of function output is:</p>

<pre><code>string 'myIterator::next' (length=16)
string 'myIterator::valid' (length=17)
</code></pre>

<p>My question is:</p>

<ol>
<li>there are 5 functions: <code>rewind();current(); key(); next(); valid();</code> why some functions seems not execute sometimes? eg, we can not see <code>myIterator::next</code> in the 1st function output. and also <code>rewind()</code> only shows one time.</li>
<li>there are 3 values in $array, so supposed foreach only run 3 times, but we can see <code>string 'myIterator::valid' (length=17)</code> appear 4 times, why?</li>
</ol>
