©
本文档使用 PHP中文网手册 发布
(PHP 5)
ReflectionMethod 类报告了一个方法的有关信息。
$class
, string $name
)$class
, string $name
[, bool $return
= false
] )$object
)$object
[, mixed $parameter
[, mixed $...
]] )$object
, array $args
)$accessible
)Method name
Class name
ReflectionMethod::IS_STATIC
指示一个方法是静态(static)的。
ReflectionMethod::IS_PUBLIC
指示一个方法是 public 的。
ReflectionMethod::IS_PROTECTED
指示一个方法是 protected 的。
ReflectionMethod::IS_PRIVATE
指示一个方法是 private 的。
ReflectionMethod::IS_ABSTRACT
指示一个方法是 abstract 的。
ReflectionMethod::IS_FINAL
指示一个方法是 final 的。
[#1] webseiten dot designer at googlemail dot com [2011-04-02 11:53:12]
Note that the public member $class contains the name of the class in which the method has been defined:
<?php
class A {public function __construct() {}}
class B extends A {}
$method = new ReflectionMethod('B', '__construct');
echo $method->class; // prints 'A'
?>
[#2] no dot prob at gmx dot net [2006-06-02 01:09:12]
I have written a function which returns the value of a given DocComment tag.
Full example:
<?php
header('Content-Type: text/plain');
class Example
{
public function myMethod()
{
echo 'Hello World!';
}
}
function getDocComment($str, $tag = '')
{
if (empty($tag))
{
return $str;
}
$matches = array();
preg_match("/".$tag.":(.*)(\\r\\n|\\r|\\n)/U", $str, $matches);
if (isset($matches[1]))
{
return trim($matches[1]);
}
return '';
}
$method = new ReflectionMethod('Example', 'myMethod');
// will return Hello World!
echo getDocComment($method->getDocComment(), '@DocTag');
?>
Maybe you can add this functionality to the getDocComment methods of the reflection classes.