<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Call a static method and pass the arguments as array</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.create-function.html">create_function</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.forward-static-call.html">forward_static_call</a></div> <div class="up"><a href="ref.funchand.html">Function handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.forward-static-call-array" class="refentry"> <div class="refnamediv"> <h1 class="refname">forward_static_call_array</h1> <p class="verinfo">(PHP 5 >= 5.3.0)</p><p class="refpurpose"><span class="refname">forward_static_call_array</span> — <span class="dc-title">Call a static method and pass the arguments as array</span></p> </div> <div class="refsect1 description" id="refsect1-function.forward-static-call-array-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>forward_static_call_array</strong></span> ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$function</code></span> , <span class="methodparam"><span class="type">array</span> <code class="parameter">$parameters</code></span> )</div> <p class="para rdfs-comment"> Calls a user defined function or method given by the <em><code class="parameter">function</code></em> parameter. This function must be called within a method context, it can't be used outside a class. It uses the <a href="language.oop5.late-static-bindings.html" class="link">late static binding</a>. All arguments of the forwarded method are passed as values, and as an array, similarly to <span class="function"><a href="function.call-user-func-array.html" class="function">call_user_func_array()</a></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.forward-static-call-array-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">function</code></em></span> <dd> <p class="para"> The function or method to be called. This parameter may be an <span class="type"><a href="language.types.array.html" class="type array">array</a></span>, with the name of the class, and the method, or a <span class="type"><a href="language.types.string.html" class="type string">string</a></span>, with a function name. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">parameter</code></em></span> <dd> <p class="para"> One parameter, gathering all the method parameter in one array. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Note that the parameters for <span class="function"><strong>forward_static_call_array()</strong></span> are not passed by reference. </p> </p></blockquote> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.forward-static-call-array-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the function result, or <strong><code>FALSE</code></strong> on error. </p> </div> <div class="refsect1 examples" id="refsect1-function.forward-static-call-array-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5106"> <p><strong>Example #1 <span class="function"><strong>forward_static_call_array()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br /> const </span><span style="color: #0000BB">NAME </span><span style="color: #007700">= </span><span style="color: #DD0000">'A'</span><span style="color: #007700">;<br /> public static function </span><span style="color: #0000BB">test</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$args </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br /> echo static::</span><span style="color: #0000BB">NAME</span><span style="color: #007700">, </span><span style="color: #DD0000">" "</span><span style="color: #007700">.</span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">, </span><span style="color: #0000BB">$args</span><span style="color: #007700">).</span><span style="color: #DD0000">" \n"</span><span style="color: #007700">;<br /> }<br />}<br /><br />class </span><span style="color: #0000BB">B </span><span style="color: #007700">extends </span><span style="color: #0000BB">A<br /></span><span style="color: #007700">{<br /> const </span><span style="color: #0000BB">NAME </span><span style="color: #007700">= </span><span style="color: #DD0000">'B'</span><span style="color: #007700">;<br /><br /> public static function </span><span style="color: #0000BB">test</span><span style="color: #007700">() {<br /> echo </span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">NAME</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">forward_static_call_array</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'A'</span><span style="color: #007700">, </span><span style="color: #DD0000">'test'</span><span style="color: #007700">), array(</span><span style="color: #DD0000">'more'</span><span style="color: #007700">, </span><span style="color: #DD0000">'args'</span><span style="color: #007700">));<br /> </span><span style="color: #0000BB">forward_static_call_array</span><span style="color: #007700">( </span><span style="color: #DD0000">'test'</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'other'</span><span style="color: #007700">, </span><span style="color: #DD0000">'args'</span><span style="color: #007700">));<br /> }<br />}<br /><br /></span><span style="color: #0000BB">B</span><span style="color: #007700">::</span><span style="color: #0000BB">test</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br /><br />function </span><span style="color: #0000BB">test</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$args </span><span style="color: #007700">= </span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();<br /> echo </span><span style="color: #DD0000">"C "</span><span style="color: #007700">.</span><span style="color: #0000BB">join</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">, </span><span style="color: #0000BB">$args</span><span style="color: #007700">).</span><span style="color: #DD0000">" \n"</span><span style="color: #007700">;<br /> }<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> B B more,args C other,args </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.forward-static-call-array-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.forward-static-call.html" class="function" rel="rdfs-seeAlso">forward_static_call()</a> - Call a static method</span></li> <li class="member"> <span class="function"><a href="function.call-user-func.html" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Call the callback given by the first parameter</span></li> <li class="member"> <span class="function"><a href="function.call-user-func-array.html" class="function" rel="rdfs-seeAlso">call_user_func_array()</a> - Call a callback with an array of parameters</span></li> <li class="member"> <span class="function"><a href="function.is-callable.html" class="function" rel="rdfs-seeAlso">is_callable()</a> - Verify that the contents of a variable can be called as a function</span></li> <li class="member">information about the <a href="language.pseudo-types.html#language.types.callback" class="link">callback</a> type</li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.create-function.html">create_function</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.forward-static-call.html">forward_static_call</a></div> <div class="up"><a href="ref.funchand.html">Function handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>