开发者

Weird comments above PHP function declarations

I noticed that a lot of scripts have these type of comments:

/**
 * Retrieve list of them开发者_运维知识库es with theme data in theme directory.
 *
 * The theme is broken, if it doesn't have a parent theme and is missing either
 * style.css and, or index.php. If the theme has a parent theme then it is
 * broken, if it is missing style.css; index.php is optional. The broken theme
 * list is saved in the {@link $wp_broken_themes} global, which is displayed on
 * the theme list in the administration panels.
 *
 * @since 1.5.0
 * @global array $wp_broken_themes Stores the broken themes.
 * @global array $wp_themes Stores the working themes.
 *
 * @return array Theme list with theme data.
 */
function get_themes() {
    global $wp_themes, $wp_broken_themes;

    ...

    return $wp_themes;
} 

It looks like some kind of documentation for the function, but what's up with the words prepended with @ ?

Like @since, @global, @return, @access, @param etc...?

I know what they mean, but why do they have @ in front of them? Do they need to identify with some kind of documentation app.?


It's the JavaDoc Standard. Most likely the author picked it because most IDEs automatically format it nicely.

http://en.wikipedia.org/wiki/Javadoc


Do they need to identify with some kind of documentation app.?

They are useful with auto-documentors like phpDocumentor, and in general are a good way to document your code. As wasabi has pointed out, IDE's can pick up on them as well and do some helpful stuff for you, like function argument type suggestions.

Even if you aren't documenting your code, it's a good habit to be in - just don't feel the need to get carried away with it at some folks tend to do (documenting every possible thing).


It's PHPDoc, which is an adaption of the beloved Javadoc format.

These documentation formats are both somewhat more readable thanks to their enforced consistency, and useful for IDEs and automatic documentation generators such as phpdoc.


Looks like phpDocumentor which is, more or less, JavaDoc for PHP.


This is definitely PHP Documentator. The "@something" parts are used to add information to the documentation. Please see PHP Documentator's documentation for details - it even has tool for generating documentation files from comments (here) in PHP Documentator's format.

Hope that helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜