title: PHP foreach by reference causes weird glitch when going through array of objects
body: <p>I have an array of objects.  The objects mainly have a bunch of
  properties because these are meta-data objects.</p>
  
  <p>so it is like
  <code>$objects[]</code> is like a bunch of items that have properties like:
  <code>object-&gt;item1</code>, <code>object-&gt;item2</code>, etc.</p>
  
  <p>I want to add something to each of these objects, so...</p>
  
  <pre><code>foreach ($objects as &amp;$object) {
    $object-&gt;newItem=(something I compute);
  }
  </code></pre>
  
  <p>then later, I want to display these objects as a list in html.  So, I go:</p>
  
  <pre><code>foreach ($objects as $object) {
    &lt;li&gt;&lt;?php object output stuff here ?&gt;&lt;/li&gt;
  }
  </code></pre>
  
  <p>ok.  Now, it works fine, except the last object is discarded and the
  second to last object is displayed twice.  WTF??</p>
  
  <p>Does this make sense to you?</p>