title: PHP Foreach Pass by Reference: Last Element Duplicating? (Bug?)
body: <p>I just had some very strange behavior with a simple php script I was writing. I reduced it to the minimum necessary to recreate the bug:</p>
  
  <pre><code>&lt;?php
  
  $arr = array("foo",
               "bar",
               "baz");
  
  foreach ($arr as &amp;$item) { /* do nothing by reference */ }
  print_r($arr);
  
  foreach ($arr as $item) { /* do nothing by value */ }
  print_r($arr); // $arr has changed....why?
  
  ?&gt;
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>Array
  (
      [0] =&gt; foo
      [1] =&gt; bar
      [2] =&gt; baz
  )
  Array
  (
      [0] =&gt; foo
      [1] =&gt; bar
      [2] =&gt; bar
  )
  </code></pre>
  
  <p>Is this a bug or some really strange behavior that is supposed to happen?</p>