PHP Portal » PHP Handbuch » ReflectionFunction::__construct

Werbung

ReflectionFunction::__construct


(PHP 5)

ReflectionFunction::__constructConstructs a ReflectionFunction object

Beschreibung

ReflectionFunction::__construct ( string $name )

Constructs a ReflectionFunction object.

Parameter-Liste

name

The name of the function to reflect.

Rückgabewerte

Es wird kein Wert zurückgegeben.

Fehler/Exceptions

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

Beispiele

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/** * 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)); }

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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

Siehe auch