title: ArrayObject::offsetUnset advances the internal pointer in an unexpected way
body: <p>Hey guys i've the following scenario</p>
  
  <pre><code>$col = new ArrayObject();
  
  for ($i = 0; $i &lt; 5; $i++)
  {
      $objItem = new stdClass;
      $objItem-&gt;someVar = $i;
      $col-&gt;append($objItem);
  }
  </code></pre>
  
  <p>Now i want to remove some key via <code>offsetUnset</code> and did the following</p>
  
  <pre><code>foreach($col AS $key =&gt; $objItem)
  {
      if ($key == 2)
      {
          $col-&gt;offsetUnset($key);
      }
      echo $key.'\n';
  }
  </code></pre>
  
  <p>The funpart now is the unexpected output</p>
  
  <pre><code>0
  1
  2
  4
  </code></pre>
  
  <p>For a better illustration - if you put a continue in like </p>
  
  <pre><code>foreach($col AS $key =&gt; $objItem)
  {
      if ($key == 2)
      {
          $col-&gt;offsetUnset($key);
          continue;
      }
      echo $key.'\n';
  }
  </code></pre>
  
  <p>the output is</p>
  
  <pre><code>0
  1
  4
  </code></pre>
  
  <p>I never ever would've thought it bypasses the <code>key</code> number <code>3</code> in this <code>ArrayObject</code> just because i removed the previous item - it looks like the internal pointer was incremented twice or something like that...</p>
  
  <p>Keep in mind i also tried something like</p>
  
  <pre><code>$it = $col-&gt;getIterator();
  
  foreach($it AS $key =&gt; $objItem)
  {
      if ($key == 2)
      {
          $col-&gt;offsetUnset($key);
      }
      echo $key."\n";
  }
  </code></pre>
  
  <p>the output is the same</p>
  
  <p>Question:</p>
  
  <blockquote>
    <p>Is this a normal behavior or do i overlook something crucial here?</p>
  </blockquote>
  
  <p>pS: As nigel Ren pointed out this as a possible duplicate of <a href="https://stackoverflow.com/questions/12409990/php-spl-arrayiterator">Php, Spl, ArrayIterator</a>, i've to point out i was looking here for an ArrayObject solution and didn't found any (i now know the ArrayIterator problem is probably the same) - but i would've never guessed that those are related to each other - in this respect i plead for not closing this question because it might help others too</p>