(PHP 5)
ReflectionFunction::__construct — Construit un nouvel objet ReflectionFunction
Construit un nouvel objet ReflectionFunction.
Le nom de la fonction à refléter.
Aucune valeur n'est retournée.
Une exception ReflectionException si le paramètre name contient une fonction invalide.
Exemple #1 Exemple avec ReflectionFunction::__construct
<?php
/**
* Un simple compteur
*
* @return int
*/
function counter()
{
static $c = 0;
return ++$c;
}
// Crée une instance de la classe ReflectionFunction
$func = new ReflectionFunction('counter');
// Affiche quelques informations
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())
{
printf("---> Static variables: %s\n", var_export($statics, 1));
}
?>
L'exemple ci-dessus va afficher quelque chose de similaire à :
===> The user-defined function 'counter' declared in /Users/philip/test.php lines 7 to 11 ---> Documentation: '/** * A simple counter * * @return int */' ---> Static variables: array ( 'c' => 0, )