<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.reflectionfunction.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'reflectionfunction.construct.php',
    1 => 'ReflectionFunction::__construct',
    2 => 'Constructs a ReflectionFunction object',
  ),
  'up' => 
  array (
    0 => 'class.reflectionfunction.php',
    1 => 'ReflectionFunction',
  ),
  'prev' => 
  array (
    0 => 'class.reflectionfunction.php',
    1 => 'ReflectionFunction',
  ),
  'next' => 
  array (
    0 => 'reflectionfunction.export.php',
    1 => 'ReflectionFunction::export',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/reflection/reflectionfunction/construct.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>

 <div class="refsect1 description" id="refsect1-reflectionfunction.construct-description">
  <h3 class="title">Description</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionFunction::__construct</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span>|<span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$function</code></span>)</div>

  <p class="para rdfs-comment">
   Constructs a <span class="classname"><a href="class.reflectionfunction.php" class="classname">ReflectionFunction</a></span> object.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionfunction.construct-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">function</code></dt>
     <dd>
      <p class="para">
       The name of the function to reflect or a <a href="functions.anonymous.php" class="link">closure</a>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-reflectionfunction.construct-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">function</code>
   parameter does not contain a valid function.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-reflectionfunction.construct-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="methodname"><strong>ReflectionFunction::__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: #FF8000">/**<br /> * A simple counter<br /> *<br /> * @return    int<br /> */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">counter1</span><span style="color: #007700">()<br />{<br />    static </span><span style="color: #0000BB">$c </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />    return ++</span><span style="color: #0000BB">$c</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">/**<br /> * Another simple counter<br /> *<br /> * @return    int<br /> */<br /></span><span style="color: #0000BB">$counter2 </span><span style="color: #007700">= function()<br />{<br />    static </span><span style="color: #0000BB">$d </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />    return ++</span><span style="color: #0000BB">$d</span><span style="color: #007700">;<br /><br />};<br /><br />function </span><span style="color: #0000BB">dumpReflectionFunction</span><span style="color: #007700">(</span><span style="color: #0000BB">$func</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">"\n\n===&gt; The %s function '%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: #0000BB">$func</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">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getFileName</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getStartLine</span><span style="color: #007700">(),<br />        </span><span style="color: #0000BB">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getEndline</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">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getDocComment</span><span style="color: #007700">(), </span><span style="color: #0000BB">1</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">$func</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getStaticVariables</span><span style="color: #007700">())<br />    {<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">1</span><span style="color: #007700">));<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// Create an instance of the ReflectionFunction class<br /></span><span style="color: #0000BB">dumpReflectionFunction</span><span style="color: #007700">(new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #DD0000">'counter1'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">dumpReflectionFunction</span><span style="color: #007700">(new </span><span style="color: #0000BB">ReflectionFunction</span><span style="color: #007700">(</span><span style="color: #0000BB">$counter2</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
something similar to:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">===&gt; The user-defined function &#039;counter1&#039;
     declared in Z:\reflectcounter.php
     lines 7 to 11
---&gt; Documentation:
 &#039;/**
 * A simple counter
 *
 * @return    int
 */&#039;
---&gt; Static variables: array (
  &#039;c&#039; =&gt; 0,
)


===&gt; The user-defined function &#039;{closure}&#039;
     declared in Z:\reflectcounter.php
     lines 18 to 23
---&gt; Documentation:
 &#039;/**
 * Another simple counter
 *
 * @return    int
 */&#039;
---&gt; Static variables: array (
  &#039;d&#039; =&gt; 0,
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionfunction.construct-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="reflectionmethod.construct.php" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::__construct()</a> - Constructs a ReflectionMethod</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); ?>