This can be done by using the getDocComment
, that is present in the classes ReflectionMethod
and ReflectionFunction
.
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 method getMethod
, an instance of ReflectionMethod
is returned.
Observing
Remember that for Docblock to be captured, it is necessary that the comment contains two asterisks after the /
.
Correct example:
/**
* @param string $value
**/
public function correto($value) {}
/*
*
*/
public function invalido($value) {}
http://www.phpdoc.org/ serves?
– Guilherme Lautert
@Guilhermelautert, I think I expressed myself badly or you didn’t understand. I want to return the contents of the docblock method
Stack::overlow
in a string. That’s it?– Wallace Maxters