<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'reflectionmethod.construct.php',
    1 => 'ReflectionMethod::__construct',
    2 => 'Constructs a ReflectionMethod',
  ),
  'up' => 
  array (
    0 => 'class.reflectionmethod.php',
    1 => 'ReflectionMethod',
  ),
  'prev' => 
  array (
    0 => 'class.reflectionmethod.php',
    1 => 'ReflectionMethod',
  ),
  'next' => 
  array (
    0 => 'reflectionmethod.createfrommethodname.php',
    1 => 'ReflectionMethod::createFromMethodName',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionmethod/construct.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>

 <div class="refsect1 description" id="refsect1-reflectionmethod.construct-description">
  <h3 class="title">Beschreibung</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionMethod::__construct</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.object.php" class="type object">object</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$objectOrMethod</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$method</code></span>)</div>

  <p class="simpara">Alternative signature (not supported with named arguments):</p>
  <div class="constructorsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>ReflectionMethod::__construct</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$classMethod</code></span>)</div>

  <div class="warning"><strong class="warning">Warnung</strong>
   <p class="simpara">
    The alternative signature is deprecated as of PHP 8.4.0,
    use <span class="methodname"><a href="reflectionmethod.createfrommethodname.php" class="methodname">ReflectionMethod::createFromMethodName()</a></span>
    instead.
   </p>
  </div>
  <p class="para">
   Constructs a new <span class="classname"><a href="class.reflectionmethod.php" class="classname">ReflectionMethod</a></span>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionmethod.construct-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">objectOrMethod</code></dt>
     <dd>
      <p class="para">
       Classname or object (instance of the class) that contains the method.
      </p>
     </dd>
    
    
     <dt><code class="parameter">method</code></dt>
     <dd>
      <p class="para">
       Name of the method.
      </p>
     </dd>
    
    
     <dt><code class="parameter">classMethod</code></dt>
     <dd>
      <p class="para">
       Class name and method name delimited by <code class="literal">::</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-reflectionmethod.construct-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="para">
   A <span class="classname"><a href="class.reflectionexception.php" class="classname">ReflectionException</a></span> is thrown if the given method does not exist.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionmethod.construct-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="methodname"><strong>ReflectionMethod::__construct()</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">Counter<br /></span><span style="color: #007700">{<br />    private static </span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /><br />    </span><span style="color: #FF8000">/**<br />     * Increment counter<br />     *<br />     * @final<br />     * @static<br />     * @access  public<br />     * @return  int<br />     */<br />    </span><span style="color: #007700">final public static function </span><span style="color: #0000BB">increment</span><span style="color: #007700">()<br />    {<br />        return ++</span><span style="color: #0000BB">self</span><span style="color: #007700">::</span><span style="color: #0000BB">$c</span><span style="color: #007700">;<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// Create an instance of the ReflectionMethod class<br /></span><span style="color: #0000BB">$method </span><span style="color: #007700">= new </span><span style="color: #0000BB">ReflectionMethod</span><span style="color: #007700">(</span><span style="color: #DD0000">'Counter'</span><span style="color: #007700">, </span><span style="color: #DD0000">'increment'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Print out basic information<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(<br />    </span><span style="color: #DD0000">"===&gt; The %s%s%s%s%s%s%s method '%s' (which is %s)\n" </span><span style="color: #007700">.<br />    </span><span style="color: #DD0000">"     declared in %s\n" </span><span style="color: #007700">.<br />    </span><span style="color: #DD0000">"     lines %d to %d\n" </span><span style="color: #007700">.<br />    </span><span style="color: #DD0000">"     having the modifiers %d[%s]\n"</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isInternal</span><span style="color: #007700">() ? </span><span style="color: #DD0000">'internal' </span><span style="color: #007700">: </span><span style="color: #DD0000">'user-defined'</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isAbstract</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' abstract' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isFinal</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' final' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isPublic</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' public' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isPrivate</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' private' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isProtected</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' protected' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isStatic</span><span style="color: #007700">() ? </span><span style="color: #DD0000">' static' </span><span style="color: #007700">: </span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isConstructor</span><span style="color: #007700">() ? </span><span style="color: #DD0000">'the constructor' </span><span style="color: #007700">: </span><span style="color: #DD0000">'a regular method'</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getFileName</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getStartLine</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getEndline</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getModifiers</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">' '</span><span style="color: #007700">, </span><span style="color: #0000BB">Reflection</span><span style="color: #007700">::</span><span style="color: #0000BB">getModifierNames</span><span style="color: #007700">(</span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getModifiers</span><span style="color: #007700">()))<br />);<br /><br /></span><span style="color: #FF8000">// Print documentation comment<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"---&gt; Documentation:\n %s\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDocComment</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Print static variables if existant<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$statics</span><span style="color: #007700">= </span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getStaticVariables</span><span style="color: #007700">()) {<br />    </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"---&gt; Static variables: %s\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$statics</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">// Invoke the method<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"---&gt; Invocation results in: "</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$method</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">invoke</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">===&gt; The user-defined final public static method &#039;increment&#039; (which is a regular method)
     declared in /Users/philip/cvs/phpdoc/test.php
     lines 14 to 17
     having the modifiers 261[final public static]
---&gt; Documentation:
 &#039;/**
     * Increment counter
     *
     * @final
     * @static
     * @access  public
     * @return  int
     */&#039;
---&gt; Invocation results in: int(1)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionmethod.construct-seealso">
  <h3 class="title">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionmethod.export.php" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::export()</a> - Export a reflection method</span></li>
    <li><a href="language.oop5.decon.php#language.oop5.decon.constructor" class="link">Constructors</a></li>
   </ul>
  </p>
 </div>


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