mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Constructor's parameter supports closures as of PHP5.3.0.
Updated example and added changelog. Fix bug #52996 git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@304139 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
533ebf53f0
commit
512ae805f6
1 changed files with 80 additions and 26 deletions
|
@ -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');
|
||||
|
||||
// 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));
|
||||
|
||||
// Print static variables if existant
|
||||
if ($statics = $func->getStaticVariables())
|
||||
/**
|
||||
* Another simple counter
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
$counter2 = function()
|
||||
{
|
||||
printf("---> Static variables: %s\n", var_export($statics, 1));
|
||||
static $d = 0;
|
||||
return ++$d;
|
||||
|
||||
};
|
||||
|
||||
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 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 @@ if ($statics = $func->getStaticVariables())
|
|||
---> 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>
|
||||
|
|
Loading…
Reference in a new issue