Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Updated Answer:</strong></p> <p>You can use:</p> <pre><code>call_user_func('more', &amp;$count) </code></pre> <p>to achieve the same effect as:</p> <pre><code>call_user_func_array('more', array(&amp;$count)) </code></pre> <p>For this reason I believe (unfoundedly) that <code>call_user_func</code> is just a compiler time short cut. (i.e. it gets replaced with the later at compile time)</p> <p>To give my view on you actual question "Why was <code>call_user_func</code> designed to work this way?":</p> <p>It probably falls under the same lines as "Why is some methods <code>strstr</code> and other <code>str_replace</code>?, why is array functions <code>haystack, needle</code> and string functions <code>needle, haystack</code>?</p> <p>Its because PHP was designed, by many different people, over a long period of time, and with no strict standards in place at the time.</p> <p><strong>Original Answer:</strong></p> <p>You must make sure you set the variable inside the array to a reference as well.</p> <p>Try this and take note of the <code>array(&amp;$t)</code> part:</p> <pre><code>function test(&amp;$t) { $t++; echo '$t is '.$t.' inside function'.PHP_EOL; } $t = 0; echo '$t is '.$t.' in global scope'.PHP_EOL; test($t); $t++; echo '$t is '.$t.' in global scope'.PHP_EOL; call_user_func_array('test', array(&amp;$t)); $t++; echo '$t is '.$t.' in global scope'.PHP_EOL; </code></pre> <p>Should output:</p> <pre><code>$t is 0 in global scope $t is 1 inside function $t is 2 in global scope $t is 3 inside function $t is 4 in global scope </code></pre>
 

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