/**
* 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();
/**
* 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();
Just to update the answers. You may also want to check out the phpDocumentor2 project. I think that it's PHP DocBlock parser can be easily extracted as standalone solution.
发布评论
评论(4)
您可以使用 Reflection API 轻松完成此操作:
请参阅本教程:http://www.phpriot.com/articles/reflection-api
还有一个 可以解析 DocBlocks 的 PEAR 包。
You can do this easily yourself with the Reflection API:
See this tutorial: http://www.phpriot.com/articles/reflection-api
There is also a PEAR package that can parse DocBlocks.
如果有人需要正则表达式(xdazz 建议尝试一下,student310评论说它适合她/他的需求)
< em>示例(演示):
In case someone needs a regular expression (xdazz suggested to try this and student310 commented it works for her/his needs)
Example (Demo):
只是为了更新答案。您可能还想查看 phpDocumentor2 项目。我认为它的 PHP DocBlock 解析器可以很容易地提取为独立的解决方案。
Just to update the answers. You may also want to check out the phpDocumentor2 project. I think that it's PHP DocBlock parser can be easily extracted as standalone solution.
正如furgas 指出的,我一直在使用phpDocumentor 作为一个独立项目多年来一直运行良好。
As furgas pointed out, I've been using phpDocumentor for years as a standalone project and it works fine.