You can do this by using the getDocComment
method, which is present in the ReflectionMethod
and ReflectionFunction
classes.
See the description of the method in Documentation .
/**
* This is an Example class
*/
class Example
{
/**
* This is an example function
*/
public function fn()
{
// void
}
}
$reflector = new ReflectionClass('Example');
// to get the Class DocBlock
echo $reflector->getDocComment()
// to get the Method DocBlock
$reflector->getMethod('fn')->getDocComment();
In the example above we use ReflectionClass
. But when we call the getMethod
method, an instance of ReflectionMethod
is returned.
Note
Note that for Docblock to be captured, the comment must contain two asterisks after /
.
Correct example:
/**
* @param string $value
**/
public function correto($value) {}
/*
*
*/
public function invalido($value) {}