Iterating over arrays inside objects is roughly 2 to 3 times slower than iterating over local vars.
So....
Code: Select all
# Note that we are inside a class here
while($something==$something_else)
{ ++$this->array; }Code: Select all
while($something==$something_else)
{ ++$array; }Well, according to something I stumbled across concerning the performance of PHP objects, there is such a thing as "True references".
Great! The are some fantastic implications to this. BUT WHY ISN'T IT IN THE MANUAL!Hi,
I'm in the process of cleaning up the use of $this-> in my code.
However, as you know, I work with COM, and it is not a good idea to set a local variable to an object, and not freeing up and releasing objects will leak memory. Thankfully, PHP4 has a feature (new to version 4) that most other languages lack... true references.
Instead of your code:
$avar = $this->avar;
Just write:
$avar =& $this->avar;
This makes $avar a true reference, and (I believe) you should be able to work with $avar in loops without performance loss as it does not have to look up the $this.
Anyways, I hope this helps someone. Plus, I'd love to hear feedback on this.
BDKR