<!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 ReflectionMethod</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.reflectionmethod.html">ReflectionMethod</a></div> <div class="next" style="text-align: right; float: right;"><a href="reflectionmethod.export.html">ReflectionMethod::export</a></div> <div class="up"><a href="class.reflectionmethod.html">ReflectionMethod</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="reflectionmethod.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">ReflectionMethod::__construct</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">ReflectionMethod::__construct</span> — <span class="dc-title">Constructs a ReflectionMethod</span></p> </div> <div class="refsect1 description" id="refsect1-reflectionmethod.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>ReflectionMethod::__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">$class</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>ReflectionMethod::__construct</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$class_method</code></span> )</div> <p class="para rdfs-comment"> Constructs a new <a href="class.reflectionmethod.html" class="classname">ReflectionMethod</a>. </p> </div> <div class="refsect1 parameters" id="refsect1-reflectionmethod.construct-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">class</code></em></span> <dd> <p class="para"> Classname or object (instance of the class) that contains the method. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">name</code></em></span> <dd> <p class="para"> Name of the method. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">class_method</code></em></span> <dd> <p class="para"> Class name and method name delimited by <em>::</em>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-reflectionmethod.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 errors" id="refsect1-reflectionmethod.construct-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> A <a href="class.reflectionexception.html" class="classname">ReflectionException</a> is thrown if the given method does not exist. </p> </div> <div class="refsect1 examples" id="refsect1-reflectionmethod.construct-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5229"> <p><strong>Example #1 <span class="methodname"><strong>ReflectionMethod::__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: #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">"===> 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">-></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">-></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">-></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">-></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">-></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">-></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">-></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">-></span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$method</span><span style="color: #007700">-></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">-></span><span style="color: #0000BB">getFileName</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$method</span><span style="color: #007700">-></span><span style="color: #0000BB">getStartLine</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$method</span><span style="color: #007700">-></span><span style="color: #0000BB">getEndline</span><span style="color: #007700">(),<br /> </span><span style="color: #0000BB">$method</span><span style="color: #007700">-></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">-></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">"---> 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">-></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">$method</span><span style="color: #007700">-></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">"---> 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 /></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">"---> 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">-></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">?></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 final public static method 'increment' (which is a regular method) declared in /Users/philip/cvs/phpdoc/test.php lines 14 to 17 having the modifiers 261[final public static] ---> Documentation: '/** * Increment counter * * @final * @static * @access public * @return int */' ---> Invocation results in: int(1) </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-reflectionmethod.construct-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="reflectionmethod.export.html" class="methodname" rel="rdfs-seeAlso">ReflectionMethod::export()</a> - Export a reflection method.</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.reflectionmethod.html">ReflectionMethod</a></div> <div class="next" style="text-align: right; float: right;"><a href="reflectionmethod.export.html">ReflectionMethod::export</a></div> <div class="up"><a href="class.reflectionmethod.html">ReflectionMethod</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>