1
0
mirror of https://github.com/php/doc-fr.git synced 2026-03-24 15:12:13 +01:00
Files
archived-doc-fr/reference/reflection/reflectionfunction/construct.xml

173 lines
4.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: ec2fe9a592f794978114ef5021db9f1d00c2e05d Maintainer: jpauli Status: ready -->
<!-- Reviewed: yes -->
<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>Construit un nouvel objet ReflectionFunction</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<constructorsynopsis role="ReflectionFunction">
<modifier>public</modifier> <methodname>ReflectionFunction::__construct</methodname>
<methodparam><type class="union"><type>Closure</type><type>string</type></type><parameter>function</parameter></methodparam>
</constructorsynopsis>
<para>
Construit un nouvel objet <classname>ReflectionFunction</classname>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>function</parameter></term>
<listitem>
<para>
Le nom de la fonction à refléter ou une
<link linkend="functions.anonymous">fermeture</link>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Une exception <classname>ReflectionException</classname> si le paramètre <parameter>function</parameter>
contient une fonction invalide.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Exemple avec <methodname>ReflectionFunction::__construct</methodname></title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Un simple compteur
*
* @return int
*/
function counter1()
{
static $c = 0;
return ++$c;
}
/**
* Un autre simple compteur
*
* @return int
*/
$counter2 = function()
{
static $d = 0;
return ++$d;
};
function dumpReflectionFunction($func)
{
// Affiche des informations basiques
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()
);
// Affiche les commentaires de documentation
printf("---> Documentation:\n %s\n", var_export($func->getDocComment(), 1));
// Affiche les variables statiques existantes
if ($statics = $func->getStaticVariables())
{
printf("---> Static variables: %s\n", var_export($statics, 1));
}
}
// Créer une instance de la classe ReflectionFunction
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:
'/**
* Un simple compteur
*
* @return int
*/'
---> Static variables: array (
'c' => 0,
)
===> The user-defined function '{closure}'
declared in Z:\reflectcounter.php
lines 18 to 23
---> Documentation:
'/**
* Un autre simple compteur
*
* @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">Les constructeurs</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
-->