Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes the following call to call_user_func_array() work?
    primarykey
    data
    text
    <p>I have a couple of libraries that use code similar to the following one.</p> <pre><code>$args = array_merge(array(&amp;$target, $context), $args); $result = call_user_func_array($callback, $args); </code></pre> <p>The code is different in both the cases, but the code I shown is what essentially is done. The <code>$callback</code> function uses the following signature:</p> <pre><code>function callback(&amp;$target, $context); </code></pre> <p>Both the libraries document that, and third-party code (call it plug-in, or extension) adopts that function signature, which means none of the extensions defines the callback as, e.g., <code>function my_extension_loader_callback($target, $context)</code>.</p> <p>What confuses me are the following sentence in the documentation for <a href="http://php.net/manual/en/function.call-user-func-array.php" rel="nofollow">call_user_func_array()</a>.</p> <blockquote> <p>Before PHP 5.4, referenced variables in param_arr are passed to the function by reference, regardless of whether the function expects the respective parameter to be passed by reference. This form of call-time pass by reference does not emit a deprecation notice, but it is nonetheless deprecated, and has been removed in PHP 5.4. <strong>Furthermore, this does not apply to internal functions, for which the function signature is honored.</strong> Passing by value when the function expects a parameter by reference results in a warning and having <code>call_user_func()</code> return <code>FALSE</code>.</p> </blockquote> <p>In particular, the highlighted sentence seems to suggest that is not done for functions define in PHP code.</p> <p>Does using <code>call_user_func_array()</code> in this way work in PHP 5.4?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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