php-doc-en/reference/reflection/reflectionfunction/construct.xml

203 lines
4.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="reflectionfunction.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>ReflectionFunction::__construct</refname>
<refpurpose>Constructs a ReflectionFunction object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<methodname>ReflectionFunction::__construct</methodname>
<methodparam><type>mixed</type><parameter>name</parameter></methodparam>
</methodsynopsis>
<para>
Constructs a <classname>ReflectionFunction</classname> object.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<para>
The name of the function to reflect or a <link linkend="functions.anonymous">closure</link>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
A <classname>ReflectionException</classname> if the <parameter>name</parameter>
parameter does not contain a valid function.
</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> can now be a <link linkend="functions.anonymous">closure</link>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><methodname>ReflectionFunction::__construct</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* A simple counter
*
* @return int
*/
function counter1()
{
static $c = 0;
return ++$c;
}
/**
* Another simple counter
*
* @return int
*/
$counter2 = function()
{
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 '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,
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>ReflectionMethod::__construct</methodname></member>
<member><link linkend="language.oop5.decon.constructor">Constructors</link></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->