<!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>Constructs a ReflectionFunction object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.reflectionfunction.html">ReflectionFunction</a></div> <div class="next" style="text-align: right; float: right;"><a href="reflectionfunction.export.html">ReflectionFunction::export</a></div> <div class="up"><a href="class.reflectionfunction.html">ReflectionFunction</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="reflectionfunction.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">ReflectionFunction::__construct</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">ReflectionFunction::__construct</span> — <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="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>ReflectionFunction::__construct</strong></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$name</code></span> )</div> <p class="para rdfs-comment"> Constructs a <a href="class.reflectionfunction.html" class="classname">ReflectionFunction</a> object. </p> </div> <div class="refsect1 parameters" id="refsect1-reflectionfunction.construct-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">name</code></em></span> <dd> <p class="para"> The name of the function to reflect or a <a href="functions.anonymous.html" class="link">closure</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-reflectionfunction.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 errors" id="refsect1-reflectionfunction.construct-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> A <a href="class.reflectionexception.html" class="classname">ReflectionException</a> if the <em><code class="parameter">name</code></em> parameter does not contain a valid function. </p> </div> <div class="refsect1 changelog" id="refsect1-reflectionfunction.construct-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.3.0</td> <td> <em><code class="parameter">name</code></em> can now be a <a href="functions.anonymous.html" class="link">closure</a>. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-reflectionfunction.construct-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5223"> <p><strong>Example #1 <span class="methodname"><strong>ReflectionFunction::__construct()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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===> 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">-></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">-></span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$func</span><span style="color: #007700">-></span><span style="color: #0000BB">getFileName</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$func</span><span style="color: #007700">-></span><span style="color: #0000BB">getStartLine</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$func</span><span style="color: #007700">-></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">"---> 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">-></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">-></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">"---> 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">?></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="cdata"><pre> ===> The user-defined function 'counter1' declared in Z:\reflectcounter.php lines 7 to 11 ---> Documentation: '/** * A simple counter * * @return int */' ---> Static variables: array ( 'c' => 0, ) ===> The user-defined function '{closure}' declared in Z:\reflectcounter.php lines 18 to 23 ---> Documentation: '/** * Another simple counter * * @return int */' ---> Static variables: array ( 'd' => 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 class="member"> <span class="methodname"><a href="reflectionmethod.construct.html" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::__construct()</a> - Constructs a ReflectionMethod</span></li> <li class="member"><a href="language.oop5.decon.html#language.oop5.decon.constructor" class="link">Constructors</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.reflectionfunction.html">ReflectionFunction</a></div> <div class="next" style="text-align: right; float: right;"><a href="reflectionfunction.export.html">ReflectionFunction::export</a></div> <div class="up"><a href="class.reflectionfunction.html">ReflectionFunction</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>