svn: /phpdoc/en/trunk/reference/reflection/reflectionfunction/ construct.xml

From: Date: Wed, 06 Oct 2010 10:33:44 +0000
Subject: svn: /phpdoc/en/trunk/reference/reflection/reflectionfunction/ construct.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-7190@lists.php.net to get a copy of this message
rquadling Wed, 06 Oct 2010 10:33:44 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=304139 Log: Constructor's parameter supports closures as of PHP5.3.0. Updated example and added changelog. Fix bug #52996 Bug: http://bugs.php.net/52996 (Assigned) Wrong parameter type in ReflectionFunction::_construct() Changed paths: U phpdoc/en/trunk/reference/reflection/reflectionfunction/construct.xml Modified: phpdoc/en/trunk/reference/reflection/reflectionfunction/construct.xml =================================================================== --- phpdoc/en/trunk/reference/reflection/reflectionfunction/construct.xml 2010-10-06 10:15:46 UTC (rev 304138) +++ phpdoc/en/trunk/reference/reflection/reflectionfunction/construct.xml 2010-10-06 10:33:44 UTC (rev 304139) @@ -11,7 +11,7 @@ &reftitle.description; <methodsynopsis> <methodname>ReflectionFunction::__construct</methodname> - <methodparam><type>string</type><parameter>name</parameter></methodparam> + <methodparam><type>mixed</type><parameter>name</parameter></methodparam> </methodsynopsis> <para> Constructs a <classname>ReflectionFunction</classname> object. @@ -26,7 +26,7 @@ <term><parameter>name</parameter></term> <listitem> <para> - The name of the function to reflect. + The name of the function to reflect or a <link linkend="functions.anonymous">closure</link>. </para> </listitem> </varlistentry> @@ -49,6 +49,30 @@ </para> </refsect1> + <refsect1 role="changelog"> + &reftitle.changelog; + <para> + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>&Version;</entry> + <entry>&Description;</entry> + </row> + </thead> + <tbody> + <row> + <entry>5.3.0</entry> + <entry> + <parameter>name</parameter> now allows <link linkend="functions.anonymous">closures</link>. + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + </refsect1> + <refsect1 role="examples"> &reftitle.examples; <para> @@ -62,43 +86,59 @@ * * @return int */ -function counter() +function counter1() { static $c = 0; return ++$c; } -// Create an instance of the ReflectionFunction class -$func = new ReflectionFunction('counter'); +/** + * Another simple counter + * + * @return int + */ +$counter2 = function() +{ + static $d = 0; + return ++$d; -// Print out basic information -printf( - "===> The %s function '%s'\n". - " declared in %s\n". - " lines %d to %d\n", - $func->isInternal() ? 'internal' : 'user-defined', - $func->getName(), - $func->getFileName(), - $func->getStartLine(), - $func->getEndline() -); +}; -// Print documentation comment -printf("---> Documentation:\n %s\n", var_export($func->getDocComment(), 1)); +function dumpReflectionFunction($func) +{ + // Print out basic information + printf( + "\n\n===> The %s function '%s'\n". + " declared in %s\n". + " lines %d to %d\n", + $func->isInternal() ? 'internal' : 'user-defined', + $func->getName(), + $func->getFileName(), + $func->getStartLine(), + $func->getEndline() + ); -// Print static variables if existant -if ($statics = $func->getStaticVariables()) -{ - printf("---> Static variables: %s\n", var_export($statics, 1)); + // Print documentation comment + printf("---> Documentation:\n %s\n", var_export($func->getDocComment(), 1)); + + // Print static variables if existant + if ($statics = $func->getStaticVariables()) + { + printf("---> Static variables: %s\n", var_export($statics, 1)); + } } + +// Create an instance of the ReflectionFunction class +dumpReflectionFunction(new ReflectionFunction('counter1')); +dumpReflectionFunction(new ReflectionFunction($counter2)); ?> ]]> </programlisting> &example.outputs.similar; <screen> <![CDATA[ -===> The user-defined function 'counter' - declared in /Users/philip/test.php +===> The user-defined function 'counter1' + declared in Z:\reflectcounter.php lines 7 to 11 ---> Documentation: '/** @@ -109,6 +149,20 @@ ---> 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, +) ]]> </screen> </example>

« previous php.doc.cvs (#7190) next »