diff --git a/reference/reflection/reflectionfunction/construct.xml b/reference/reflection/reflectionfunction/construct.xml index 4efbcd48e4..654aad9d2a 100644 --- a/reference/reflection/reflectionfunction/construct.xml +++ b/reference/reflection/reflectionfunction/construct.xml @@ -11,7 +11,7 @@ &reftitle.description; ReflectionFunction::__construct - stringname + mixedname Constructs a ReflectionFunction object. @@ -26,7 +26,7 @@ name - The name of the function to reflect. + The name of the function to reflect or a closure. @@ -49,6 +49,30 @@ + + &reftitle.changelog; + + + + + + &Version; + &Description; + + + + + 5.3.0 + + name now allows closures. + + + + + + + + &reftitle.examples; @@ -62,43 +86,59 @@ * * @return int */ -function counter() +function counter1() { 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()) +/** + * Another simple counter + * + * @return int + */ +$counter2 = function() { - printf("---> Static variables: %s\n", var_export($statics, 1)); + static $d = 0; + return ++$d; + +}; + +function dumpReflectionFunction($func) +{ + // Print out basic information + printf( + "\n\n===> 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)); + } } + +// Create an instance of the ReflectionFunction class +dumpReflectionFunction(new ReflectionFunction('counter1')); +dumpReflectionFunction(new ReflectionFunction($counter2)); ?> ]]> &example.outputs.similar; The user-defined function 'counter' - declared in /Users/philip/test.php +===> The user-defined function 'counter1' + declared in Z:\reflectcounter.php lines 7 to 11 ---> Documentation: '/** @@ -109,6 +149,20 @@ if ($statics = $func->getStaticVariables()) ---> Static variables: array ( 'c' => 0, ) + + +===> The user-defined function '{closure}' + declared in Z:\reflectcounter.php + lines 18 to 23 +---> Documentation: + '/** + * Another simple counter + * + * @return int + */' +---> Static variables: array ( + 'd' => 0, +) ]]>