<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionmethod.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'reflectionmethod.invoke.php',
    1 => 'ReflectionMethod::invoke',
    2 => 'Invoke',
  ),
  'up' => 
  array (
    0 => 'class.reflectionmethod.php',
    1 => 'ReflectionMethod',
  ),
  'prev' => 
  array (
    0 => 'reflectionmethod.hasprototype.php',
    1 => 'ReflectionMethod::hasPrototype',
  ),
  'next' => 
  array (
    0 => 'reflectionmethod.invokeargs.php',
    1 => 'ReflectionMethod::invokeArgs',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionmethod/invoke.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="reflectionmethod.invoke" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionMethod::invoke</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionMethod::invoke</span> &mdash; <span class="dc-title">Invoke</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionmethod.invoke-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionMethod::invoke</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.object.php" class="type object">object</a></span></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">...$args</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   Invokes a reflected method.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionmethod.invoke-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">object</code></dt>
     <dd>
      <p class="para">
       The object to invoke the method on. For static methods, pass
       <span class="type"><a href="language.types.null.php" class="type null">null</a></span> to this parameter.
      </p>
     </dd>
    
    
     <dt><code class="parameter">args</code></dt>
     <dd>
      <p class="para">
       Zero or more parameters to be passed to the method.
       It accepts a variable number of parameters which are passed to the method.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionmethod.invoke-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the method result.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-reflectionmethod.invoke-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   A <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span> if the <code class="parameter">object</code>
   parameter does not contain an instance of the class that this method was declared in.
  </p>
  <p class="para">
   A <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span> if the method invocation failed.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionmethod.invoke-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="methodname"><strong>ReflectionMethod::invoke()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">HelloWorld </span><span style="color: #007700">{<br /><br />    public function </span><span style="color: #0000BB">sayHelloTo</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">) {<br />        return </span><span style="color: #DD0000">'Hello ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br />    }<br /><br />}<br /><br /></span><span style="color: #0000BB">$reflectionMethod </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionMethod</span><span style="color: #007700">(</span><span style="color: #DD0000">'HelloWorld'</span><span style="color: #007700">, </span><span style="color: #DD0000">'sayHelloTo'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$reflectionMethod</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">invoke</span><span style="color: #007700">(new </span><span style="color: #0000BB">HelloWorld</span><span style="color: #007700">(), </span><span style="color: #DD0000">'Mike'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Hello Mike</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-reflectionmethod.invoke-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="methodname"><strong>ReflectionMethod::invoke()</strong></span> cannot be used when reference parameters are expected.
    <span class="methodname"><a href="reflectionmethod.invokeargs.php" class="methodname">ReflectionMethod::invokeArgs()</a></span> has to be used instead (passing references in the argument list).
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionmethod.invoke-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionmethod.invokeargs.php" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::invokeArgs()</a> - Invoke args</span></li>
    <li><a href="language.oop5.magic.php#object.invoke" class="link">__invoke()</a></li>
    <li><span class="function"><a href="function.call-user-func.php" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Call the callback given by the first parameter</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>