Re: Return Values Copied? Copied if By Reference?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, July 27, 2006 1:05 pm, Adam Zey wrote:
> Then how come when I do a foreach on an array (without modifying
> anything within the foreach), it still makes a copy of the array that
> consumes memory? I think it's dangerous to generalize that it's always
> best to let PHP make copies of things. In the foreach situation, the
> preferred solution when memory is a problem is to either use a
> reference, or have foreach iterate over the keys of the array.

I think this is because you can sometimes use & to modify the contents
of the iteratee (is that a word?) so PHP does a copy there blindly,
whether you have & or not, because you might have & there sometimes.

I think Dmitry or Antony or ??? is looking at changing that so the
copy is only done when & is present.

At least, that's how I understand (or not) the upshot of a thread on
Internals.

It's entirely possible, even likely, that I'm completely
misunderstanding both of these threads. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux