PHP 注释规范

402 阅读9分钟

PHP 注释规范

注释在写代码的过程中非常重要,好的注释能让你的代码读起来更轻松,在写代码的时候一定要注意注释的规范。

php里面常见的几种注释方式:

1.文件头的注释,介绍文件名,功能以及作者版本号等信息

/***********************************************************************************************
 ***       O W E N -- W E B    I N T E R N E T    T E C H N O L O G Y    C O.,L T D          ***
 ***********************************************************************************************
 *                                                                                             *
 *                      Project Name : Cmit & Sports                                           *
 *                                                                                             *
 *                      File Name : WormInsertAllHPTeamStats.php                               *
 *                                                                                             *
 *                      Programmer : Owen Zhang                                                *
 *                                                                                             *
 *                      Start Date : 06/17/20                                                  *
 *                                                                                             *
 *                      Last Update : 06 17, 2020 [OWEN]                                       *
 *                                                                                             *
 *---------------------------------------------------------------------------------------------*
 * Functions:                                                                                  *
 *   00 15 21 * * 2 php /home/wwwroot/kaijiang-server-dev/think WormInsertAllHPTeamStats       *
 *   每周二21点15分执行一次 hp球队赛季数据采集                                                      *
 *   wormUpdateAllTeamStanding -- hp爬取全部历史赛季球队胜负数--更新                               *
 *   wormInsertAllTeamStats -- hp爬取全部历史赛季球队数据                                         *
 *   wormUpdateAllTeamOtherStats -- hp爬取全部球队赛季其他数据                                    *
 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


/**
 * Programmer: Owen Zhang
 * Email: owenzhang@cmit.com
 * Start Date: 06/17/20
 * Last Update: 06 17, 2020 [OZ]
 * Functions:
 *      00 15 21 * * 2 php /home/wwwroot/kaijiang-server-dev/think WormInsertAllHPTeamStats
 *      每周二21点15分执行一次 hp球队赛季数据采集
 *      wormUpdateAllTeamStanding -- hp爬取全部历史赛季球队胜负数--更新
 *      wormInsertAllTeamStats -- hp爬取全部历史赛季球队数据
 *      wormUpdateAllTeamOtherStats -- hp爬取全部球队赛季其他数据
 */

2.函数的注释,函数作用,参数介绍及返回类型

/**  
* 函数的含义说明 
* @url 接口url
* @access public 
* @param int $arg1 参数一的说明 
* @param string $arg2 参数二的说明 
* @param mixed $mixed 这是一个混合类型 
* @return array 返回类型
*/  

3.类的注释,类名及介绍

/** 
* 类的介绍 
* 类的详细介绍(可选。)。 
* @author      alvin 作者 
* @version     1.0 版本号
*/

4.多行注释

/* php注释语法
   这是多行注释。*/ 

5.单行注释

$n = 10; //数量n,这是单行注释

作者:ILLYM
链接:www.zhihu.com/question/29…
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

脑洞大开

/**
* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you. Never gonna make you cry,
* never gonna say goodbye. Never gonna tell a lie and hurt you.
*/

历史的教训

// 
// Dear maintainer:
// 
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// 
// total_hours_wasted_here = 42
// 

忠告

/*
 * You may think you know what the following code does.
 * But you dont. Trust me.
 * Fiddle with it, and youll spend many a sleepless
 * night cursing the moment you thought youd be clever
 * enough to "optimize" the code below.
 * Now close this file and go play with something else.
 */ 

//When I wrote this, only God and I understood what I was doing
//Now, God only knows

// I dedicate all this code, all my work, to my wife, Darlene, who will // have to support me and our three children and the dog once it gets // released into the public.

//This code sucks, you know it and I know it.
//Move on and call me an idiot later.

/***
 * 这个公司没有年终奖的,兄弟别指望了,也别来了,我准备辞职了
 * 另外这个项目有很多*Bug* 你坚持不了多久的,拜拜!
 */

作者:思否小姐姐
链接:https://www.zhihu.com/question/29962541/answer/429530482
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

/***
 * 1只羊 == one sheep
 * 2只羊 == two sheeps
 * 3只羊 == three sheeps
 * 4只羊 == four sheeps
 * 5只羊 == five sheeps
 * 6只羊 == six sheeps
 * 7只羊 == seven sheeps
 * 8只羊 == eight sheeps
 * 9只羊 == nine sheeps
 * 10只羊 == ten sheeps
 * 11只羊 == eleven sheeps
 * 12只羊 == twelve sheeps
 * 13只羊 == thirteen sheeps
 * 14只羊 == fourteen sheeps
 * 15只羊 == fifteen sheeps
 * 16只羊 == sixteen sheeps
 * 17只羊 == seventeen sheeps
 * 18只羊 == eighteen sheeps
 * 19只羊 == nineteen sheeps
 * 20只羊 == twenty sheeps
 * 21只羊 == twenty one sheeps
 * 22只羊 == twenty two sheeps
 * 23只羊 == twenty three sheeps
 * 24只羊 == twenty four sheeps
 * 25只羊 == twenty five sheeps
 * 26只羊 == twenty six sheeps
 * 27只羊 == twenty seven sheeps
 * 28只羊 == twenty eight sheeps
 * 29只羊 == twenty nine sheeps
 * 30只羊 == thirty sheeps
 * 现在瞌睡了吧,好了,不要再改下面的代码了,睡觉咯~~
 */

/***
 * You may think you know what the following code does.
 * But you dont. Trust me.
 * Fiddle with it, and youll spend many a sleepless
 * night cursing the moment you thought youd be clever
 * enough to "optimize" the code below.
 * Now close this file and go play with something else.
 */
/***
 * 你可能会认为你读得懂以下的代码。但是你不会懂的,相信我吧。
 * 要是你尝试玩弄这段代码的话,你将会在无尽的通宵中不断地咒骂自己为什么会认为自己聪明到可以优化这段代码。
 * 现在请关闭这个文件去玩点别的吧。
 */


/***
 * somedev1 -  6/7/02 Adding temporary tracking of Login screen
 * somedev2 -  5/22/07 Temporary my ass
 */
/***
 * 一些修改1 - 2002/6/7 增加临时的跟踪登录界面
 * 一些修改2 - 2007/5/22 我临时的犯傻
 */


/***
 * 程序员1(于2010年6月7日):在这个坑临时加入一些调料
 * 程序员2(于2011年5月22日):临你个屁啊
 * 程序员3(于2012年7月23日):楼上都是狗屎,鉴定完毕
 * 程序员4(于2013年8月2日):fuck 楼上,三年了,这坑还在!!!
 * 程序员5(于2014年8月21日):哈哈哈,这坑居然坑了这么多人,幸好我也不用填了,系统终止运行了,you're died
 */


作者:思否小姐姐
链接:https://www.zhihu.com/question/29962541/answer/429530482
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

/***
 * For the brave souls who get this far: You are the chosen ones,
 * the valiant knights of programming who toil away, without rest,
 * fixing our most awful code. To you, true saviors, kings of men,
 * I say this: never gonna give you up, never gonna let you down,
 * never gonna run around and desert you. Never gonna make you cry,
 * never gonna say goodbye. Never gonna tell a lie and hurt you.
 */
/***
 * 致终于来到这里的勇敢的人:
 * 你是被上帝选中的人,是英勇的、不敌辛苦的、不眠不休的来修改我们这最棘手的代码的编程骑士。
 * 你,我们的救世主,人中之龙,我要对你说:永远不要放弃,永远不要对自己失望,永远不要逃走,辜负了自己,
 * 永远不要哭啼,永远不要说再见,永远不要说谎来伤害自己。
 */


/***
 * Dear maintainer:
 *
 * Once you are done trying to 'optimize' this routine,
 * and have realized what a terrible mistake that was,
 * please increment the following counter as a warning
 * to the next guy:
 *
 * total_hours_wasted_here = 42
 */
/***
 * 亲爱的维护者:
 *
 * 如果你尝试了对这段程序进行'优化'
 * 下面这个计数器的个数用来对后来人进行警告
 *
 * 浪费在这里的总时间 = 42h
 */


/***
 * When I wrote this, only God and I understood what I was doing
 * Now, God only knows
 */
/***
* 写这段代码的时候,只有上帝和我知道它是干嘛的
* 现在,只有上帝知道
*/

// sometimes I believe compiler ignores all my comments
// 有时候我相信编译器忽略了我所有的注释

// drunk, fix later
// 有点晕了,以后再修改

// Magic. Do not touch.
// 麻鸡。勿动。



<!-- Here be dragons -->
<!-- 前方高能 -->



double penetration; // ouch
// 自行了解,不方便解释


// To understand recursion, see the bottom of this file
At the bottom of the file:
// To understand recursion, see the top of this file
// 想要明白递归须看文件末尾
到了文末
// 想要明白递归须看文件顶部



long long ago; /* in a galaxy far far away */
// 很久很久以前 在一个遥远的银河中(出自星球大战)


// This code sucks, you know it and I know it.  
// Move on and call me an idiot later.
// 你我都知道这代码很烂
// 先不要骂我2B了,请先继续往下看


// I am not sure why this works but it fixes the problem.
// 虽然我不知道为什么这样管用,但它却是修复了问题


// If this comment is removed the program will blow up
// 如果删了此处注释程序就炸了


// This function has been here since 1987. DON'T FXXKING TOUCH IT
// 这函数1987年就这在了,别他娘动它


// if i ever see this again i'm going to start bringing guns to work
// 如果要是再让我看见这样的代码,也许我会带着一把枪来上班


// no comments for you
// it was hard to write
// so it should be hard to read
// 难写的代码,肯定很难读。因此,我没有注释留给你。


// I will give you two of my seventy-two virgins if you can fix this.
// 要是你能修正这个问题的话,我会在我的七十二个处女中挑两个送你// I am not responsible of this code.
// They made me write it, against my will.
// 下面的代码,我不负责。因为是他们逼我写的,违背了我的意愿。/* You are not expected to understand this */
/* 你绝不会明白的 */// I have to find a better job
// 看来我需要找份更好的工作了/***
 * 这个类是Object的子类
 */



作者:匿名用户
链接:https://www.zhihu.com/question/29962541/answer/46229082
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
//          佛曰:  
//                  写字楼里写字间,写字间里程序员;  
//                  程序人员写程序,又拿程序换酒钱。  
//                  酒醒只在网上坐,酒醉还来网下眠;  
//                  酒醉酒醒日复日,网上网下年复年。  
//                  但愿老死电脑间,不愿鞠躬老板前;  
//                  奔驰宝马贵者趣,公交自行程序员。  
//                  别人笑我忒疯癫,我笑自己命太贱;  
//                  不见满街漂亮妹,哪个归得程序员?




/ *您不应该理解这一点* /

/* 我们并不指望你能看懂这段话 */



/** 2014-11-4鱼香肉丝 */

/** 2014-11-5糖醋排骨*/

/** 2014-11-6扬州炒饭*/

/** 2014-11-9还是糖醋排骨好吃点*/


Buy me a cup of coffee :)