Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When using <code>call_user_func_array</code>, passing by value when a function expects a reference is considered an error, in newer versions of PHP.</p> <p>This was valid PHP code before PHP 5.3.3:</p> <pre><code>//first param is pass by reference: my_function(&amp;$strName){ } //passing by value, not by reference, is now incorrect if passing by reference is expected: call_user_func_array("my_function", array($strSomething)); //correct usage call_user_func_array("my_function", array(&amp;$strSomething)); </code></pre> <p>The above pass by value is no longer possible without a warning (my project is also set to throw exceptions on any kind of error (notice, warning, etc).) so I had to fix this.</p> <p><strong>Solution</strong> I've hit this problem and this is how I solved it (I have a small RPC server, so there is no such thing as referenced values after deserializing params):</p> <pre><code>//generic utility function for this kind of situations function &amp;array_make_references(&amp;$arrSomething) { $arrAllValuesReferencesToOriginalValues=array(); foreach($arrSomething as $mxKey=&gt;&amp;$mxValue) $arrAllValuesReferencesToOriginalValues[$mxKey]=&amp;$mxValue; return $arrAllValuesReferencesToOriginalValues; } </code></pre> <p>Although <code>$strSomething</code> is not passed by reference, <code>array_make_references</code> will make it a reference to itself:</p> <pre><code>call_user_func_array("my_function", array_make_references(array($strSomething))); </code></pre> <p>I think the PHP guys were thinking of helping people catch incorrectly called functions (a well concealed pitfall), which happens often when going through <code>call_user_func_array</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload