ReflectionFunction
PHP Manual

ReflectionFunction::__construct

(PHP 5)

ReflectionFunction::__constructConstruit un nouvel objet ReflectionFunction

Description

ReflectionFunction::__construct ( string $name )

Construit un nouvel objet ReflectionFunction.

Liste de paramètres

name

Le nom de la fonction à refléter.

Valeurs de retour

Aucune valeur n'est retournée.

Erreurs / Exceptions

Une exception ReflectionException si le paramètre name contient une fonction invalide.

Exemples

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($statics1));
}
?>

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,
)

Voir aussi


ReflectionFunction
PHP Manual