In PHP, is it less resource intensive (smarter) to pass a very large amount of data by reference than by value?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/178328/in-php-5-0-is-passing-by-reference-faster">In PHP (&gt;= 5.0), is passing by reference faster?</a>  </p>
</blockquote>



<p>Say I'm dealing with a large-ish (just how big isn't important) array of data and passing it into a function. It will, of course, be passed by value and not by reference by default. Okay, I know that.</p>

<p>So my question is:</p>

<blockquote>
  <p>If the data stored in this array were large enough, can worthwhile
  performance or memory usage gains be experienced by storing the data
  in an object (say, a <strong>stdClass</strong>) or by using <strong>foo(&amp;$myData)</strong> so that the data is
  passed by reference instead of value?</p>
</blockquote>

<p>My understanding is that when it's passed by value PHP will create a whole new pointer to a whole new memory allocation for the data while the passed-by-value variable exists in the function scope. In such an event, might passing a large amount of data by reference be worthwhile for this reason? I don't know if this understanding is correct ... that's part of the question.</p>

<p><em><strong>Note:</strong> this is a hypothetical, so don't bring up anything about "premature optimization", "you'd be better off to minimize disk I/O before worrying about this", "depends on how much RAM you have", "etc."</em></p>

<p><strong>UPDATE</strong></p>

<p>A further question: say the data is being passed to an object constructor to be stored as one of that object's properties and it's being modified in some small way as it's stored in the new object's property. Will there then be a significant difference in the memory usage aspect of the operation? Is it correct to assume that it will be better to define the data in the destination format to begin with to avoid the cost incurred by altering the data down the line?</p>
