Be careful of thinking of iterators and arrays as completely analogous in your PHP code. iterator_count will NOT return your iterator to its previous state after looping through it for the count. Any iterator implementation that also implements Countable::count isn't required to do so either.
This is clearest in example form:
<?php
$array = array(
1 => 'foo',
2 => 'bar'
);
foreach ($array as $key => $value)
{
echo "$key: $value (", count($array), ")\n";
}
$iterator = new ArrayIterator($array);
foreach ($iterator as $key => $value)
{
echo "$key: $value (", iterator_count($iterator), ")\n";
}
?>
outputs:
1: foo (2)
2: bar (2)
1: foo (2)
Notice that because of how iterator_count works we never see the second iterator value because the next call to then Iterator::valid() implementation returns false (its at the end of the iterator).