php代码样式,PHP代码式样

*/"

* 单行代码也必须使用分号(;)结束

== 命名:

* 文件名使用snake_case方式,禁止使用臃肿的文件名

* 变量名使用snake_case方式,禁止使用臃肿的变量名

* 禁止使用单字符做为局部变量(如$i),在for循环中除外

* 禁止使用大写字母做为全局变量,如使用大写字母,应使用SCREAMING_SNAKE_CASE方式

* 类名使用CamelCase方式,方法名使用camelCase方式(保持像HTTP,RFC,XML缩写词的大写)

* 常量名使用SCREAMING_SNAKE_CASE方式

// badsuperclass.phpSuperClass.phpsuperClass.php$i = "foobar"; // 单字符变量只充许使用在for循环中$bufferdText // 驼峰式变量,并且意思可以再精简些$groupid // 两个单词之间需要下划线分开$name_of_last_city_used // 太长MyConstant // 应该用下划线并且字母没有全大写N // 单字符S_C_VER // 意思不清楚class superclassclass superClassfunction fileproperties() // 意思不清楚并且没有驼峰式命名function fileProperties() // 意思不清楚function getfileproperties() // 好些了,但没有驼峰式命名// goodsuper_class.phpfor ($i = 0; $i < 10; $i++)$buffer$group_id$last_cityMY_CONSTANTNEWLINESUPER_CLASS_VERSIONclass SuperClassfunction getFileProperties()

== 语法:

对于嵌入HTML中的PHP代码,对于像if, for, foreach, while等代码块,采用if: ... endif; for: ... endfor; foreach: ... endforeach;以及 while: ... endwhile;方法块

...isLoggedIn()): // checking logged in ?>...

== 注释:

* 文档块必须和phpDocumentor格式兼容,请参考: http://phpdoc.org/

* 避免多余的意见

/** * 控制器类说明信息 */class Controller { private static $instance; public function __construct() { ... } /** * 函数说明信息 */ public static function &get_instance() { ... }/* End of file controller.php */

== 其他:

* 保持代码简单

* 保持一致性

参考:CodeIgniter,ZendFramework,Wordpress等

http://codeigniter.com/user_guide/general/styleguide.html

http://framework.zend.com/manual/zh/coding-standard.coding-style.html

http://codex.wordpress.org/WordPress_Coding_Standards

其他

Github https://github.com/styleguide

HTML/CSS 代码样式(英文)

http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml

Javascript 代码样式(英文)

http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml

Ruby 样式参见(英文) https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值