title: When to pass-by-reference in PHP
body: <p>Im wondering if its good practice to pass-by-reference when you are only reading a variable, or if it should always be passed as a value.</p>
  
  <p>Example with pass-by-reference:</p>
  
  <pre><code>$a = 'fish and chips';
  $b = do_my_hash($a);
  echo $b;
  
  function &amp;do_my_hash(&amp;$value){
     return md5($value);
  }
  </code></pre>
  
  <p>Example with pass-by-value:</p>
  
  <pre><code>$a = 'fish and chips';
  $b = do_my_hash($a);
  echo $b;
  
  function do_my_hash($value){
     return md5($value);
  }
  </code></pre>
  
  <p>Which is better ? E.g if I was to run a loop with 1000 rounds ?</p>
  
  <p>Example of loop:</p>
  
  <pre><code>for($i = 0 ; $i &lt; 1000 ; $i++){
     $a = 'Fish &amp; Chips '.$i;
     echo do_my_hash($a);
  }
  </code></pre>