Re: Return Values Copied? Copied if By Reference?

From: Date: Thu, 03 Aug 2006 20:15:15 +0000
Subject: Re: Return Values Copied? Copied if By Reference?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-240081@lists.php.net to get a copy of this message
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

« previous php.general (#240081) next »