ReflectionFunction
PHP Manual

ReflectionFunction::__construct

(PHP 5)

ReflectionFunction::__constructConstructs a ReflectionFunction object

Description

ReflectionFunction::__construct ( string $name )

Constructs a ReflectionFunction object.

Parameters

name

The name of the function to reflect.

Return Values

No value is returned.

Errors/Exceptions

A ReflectionException if the name parameter does not contain a valid function.

Examples

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

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

See Also


ReflectionFunction
PHP Manual