什么是php评论中额外的星号的目的? [英] what is the purpose of the extra asterisks in php comments?
问题描述
我已经(最后)阅读了PEAR(php)编码标准。
I've (finally) been reading up on PEAR (php) coding standards.
这样评论的目的是什么:
What is the purpose of commenting like this:
/**
* Here is my comment
* I Wrote this in a haiku
* But why put the stars?
*/
与此相反:
/*
Here is a comment
No haiku or
anything special, but it still works!
*/
推荐答案
/ ** stuff * /
文档也称为 DocBlock 符号。
它用于记录PHP函数,类等。
It's used to document PHP functions, classes, etc.
/**
* A test function
*
* @param foo $bar
* @return baz
*/
function test(foo $bar) { return new baz; }
一些编辑者善用此功能来执行Code Insight功能,你必须花时间看你的旧函数声明的时间。
Some editors make good use of this to perform their Code Insight feature, a very powerful tool that reduces the time you have to spend looking at your old function declarations. Aptana and Zend Studio have this feature, probably others as well.
您也可以将它与反射做某种AOP,在你的声明上面进行DocBlock的运行时检查。事实上,Doctrine使用它来为他们构建对象属性地图 Active Record实现。
You can also use it in combination with Reflection to do some sort of AOP, doing runtime inspection of the DocBlock above your declarations. In fact, Doctrine uses it to build an object attribute map for their "Active Record" implementation.
这篇关于什么是php评论中额外的星号的目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!