douan5151 2014-09-27 11:08
浏览 13
已采纳

通过阅读函数注释自动创建文档(PHP)

Let's say I have:

class myclass {

    /*
     * This function, bla bla bla
     */
    function myclass()
    {
        return(true);
    }

    /*
     * This function, bla bla bla
     */
    function myfunc1()
    {
        return(true);
    }

    /*
     * This function, bla bla bla
     */
    function myfunc2()
    {
        return(true);
    }
}

By using get_class_methods(new myclass()); I can get the classes.

Now my question is this: can I read the comments from the class function into a string? So I can create auto generated documentation.

  • 写回答

1条回答 默认 最新

  • douling0053 2014-09-27 11:30
    关注

    You can't get access to comments from PHP it the target file is included with include, include_once, require or require_once because of php-parser strips all comments out of code.

    If you need to do it and don't want to use PHPDocumentor or Doxygen, but want to do it yourself, you need to reed the target file using file_get_contents or any other reading method and parse this code yourself using reguar expressions of other method of your choise(for example using this library - https://github.com/nikic/PHP-Parser). And parsing the code yourself you can get all information you need from comments.

    But it is not so easy task so my advice is to use PHPDocumentor :P

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?