title: PHP anonymous function variable as reference
body: <p>While working with Laravel framework, more specific - Form macros, I stumbled upon a weird error.</p>
  
  <p>At first, I thought it's something wrong with Laravel, but then I took everything out of context:</p>
  
  <pre><code>&lt;?php
  
  // placeholder function that takes variable as reference
  $function = function(&amp;$reference)
  {
      // append to variable
      $reference = $reference . ':' . __METHOD__;
  };
  
  // test with straight call
  $variable = 'something';
  $function($variable);
  echo $variable;
  
  
  // test with call_user_func(), that gets called in Laravels case
  $variable = 'something'; // reset
  call_user_func($function, $variable);
  echo $variable;
  </code></pre>
  
  <p>While the first call to <code>$function</code> executes properly, the second try with <code>call_user_func()</code>, produces (excerpt from Codepad):</p>
  
  <pre><code>Warning: Parameter 1 to {closure}() expected to be a reference, value given
  PHP Warning: Parameter 1 to {closure}() expected to be a reference, value given
  </code></pre>
  
  <p>Fiddle: <a href="http://codepad.viper-7.com/vknzNO" rel="nofollow">Codepad @ Viper-7</a></p>
  
  <p>While writing this, I thought about <code>call_user_func_array()</code>: <a href="http://codepad.viper-7.com/ay57d8" rel="nofollow">fiddle here</a>, but the same error is produced.</p>
  
  <p>Have I got something wrong about references or is this a bug with PHP?</p>