title: PHP performance: $this->variable versus local $variable (manipulating)
body: <p>I had a section in a class that I decided to split into a new one. </p>
  
  <p>When I had ported the code section into a new class I noticed it was considerably slower at executing one of the foreach loops. </p>
  
  <p>I managed to track down part of the problem to be how I decided to save the final result array.</p>
  
  <p>I think it'll be easier to understand if you see a shortened version of my code: </p>
  
  <p>The original ported code: <a href="http://pastebin.com/2iBuqmgn" rel="noreferrer">http://pastebin.com/2iBuqmgn</a>
  More optimized ported code: <a href="http://pastebin.com/TYU1rHwU" rel="noreferrer">http://pastebin.com/TYU1rHwU</a></p>
  
  <p>You'll see that in the first example I manipulate $this->active_topics directly all the way trough. </p>
  
  <p>While in the second example I use local variables before I save the local variable to $this->active_topics AFTER the foreach-loop. </p>
  
  <p>With the original a loop seemed to average to 1 second, while the more optimized one use 0.85 to execute on average. They end up returning exactly the same content.</p>
  
  <p>Why is the more optimized code, with use of local variables, more efficient?</p>