title: return large data by reference or as return in function?
body: <p>On the job today I had an arguement with a collage about passing large data between scopes.
  The myth was that reference uses less memory/CPU usage when passing between 2 scopes. We build a proof of concept who was right... so:</p>
  <pre class="lang-php prettyprint-override"><code>function by_return($dummy=null) {
      $dummy = str_repeat(&quot;1&quot;,100 * 1024 * 1024);
      return $dummy;
  }
  
  function by_reference(&amp;$dummy) {
      $dummy = null;
      $dummy = str_repeat(&quot;1&quot;,100 * 1024 * 1024);
  }
  echo memory_get_usage().&quot;/&quot;.memory_get_peak_usage().&quot;\n&quot;;
  //1 always returns: 105493696/105496656
  $nagid = by_return();
  echo memory_get_usage().&quot;/&quot;.memory_get_peak_usage().&quot;\n&quot;;
  unset($nagid);
  //2 always returns:  105493696/210354184 even if we comment 1st part
  by_reference($dummy);
  echo memory_get_usage().&quot;/&quot;.memory_get_peak_usage().&quot;\n&quot;;
  unset($dummy);
  </code></pre>
  <p>But it seems that by reference it consumes more memory according to function &quot;memory_get_peak_usage()&quot;</p>
  <p>As  you see, using large data for returning is much smarter than using as reference but the question is, why?
  Any enlightening is welcomed :)</p>