(PHP 5)
ReflectionFunction::__construct — Constructs a ReflectionFunction object
Constructs a ReflectionFunction object.
The name of the function to reflect.
No value is returned.
A ReflectionException if the name parameter does not contain a valid function.
Example #1 ReflectionFunction::__construct example
<?php
/**
* A simple counter
*
* @return int
*/
function counter()
{
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())
{
printf("---> Static variables: %s\n", var_export($statics, 1));
}
?>
The above example will output something similar to:
===> 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, )