简体   繁体   中英

Automatically create documentation by reading function comments (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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM