Php/docs/reflectionmethod.construct
ReflectionMethod::__construct
(PHP 5, PHP 7)
ReflectionMethod::__construct — ReflectionMethod 的构造函数
说明
public ReflectionMethod::__construct
( mixed $class
, string $name
)
public ReflectionMethod::__construct
( string $class_method
)
构造一个新的 ReflectionMethod
参数
class
- 包含方法的类名称或者这个类的一个实例
name
- 方法的名称
class_method
- 类名称和方法名称,之间使用
::
分隔
返回值
没有返回值。
范例
Example #1 ReflectionMethod::__construct() example
<?phpclass Counter{ private static $c = 0; /** * Increment counter * * @final * @static * @access public * @return int */ final public static function increment() { return ++self::$c; }}// Create an instance of the ReflectionMethod class$method = new ReflectionMethod('Counter', 'increment');// Print out basic informationprintf( "===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n" . " declared in %s\n" . " lines %d to %d\n" . " having the modifiers %d[%s]\n", $method->isInternal() ? 'internal' : 'user-defined', $method->isAbstract() ? ' abstract' : , $method->isFinal() ? ' final' : , $method->isPublic() ? ' public' : , $method->isPrivate() ? ' private' : , $method->isProtected() ? ' protected' : , $method->isStatic() ? ' static' : , $method->getName(), $method->isConstructor() ? 'the constructor' : 'a regular method', $method->getFileName(), $method->getStartLine(), $method->getEndline(), $method->getModifiers(), implode(' ', Reflection::getModifierNames($method->getModifiers())));// 打印注释文档printf("---> Documentation:\n %s\n", var_export($method->getDocComment(), 1));// 打印存在的静态变量if ($statics= $method->getStaticVariables()) { printf("---> Static variables: %s\n", var_export($statics, 1));}// 执行方法printf("---> Invocation results in: ");var_dump($method->invoke(NULL));?>
以上例程的输出类似于:
===> The user-defined final public static method 'increment' (which is a regular method) declared in /Users/philip/cvs/phpdoc/test.php lines 14 to 17 having the modifiers 261[final public static] ---> Documentation: '/** * Increment counter * * @final * @static * @access public * @return int */' ---> Invocation results in: int(1)