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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办