花花世界蕾 发表于 2017-3-23 07:58:19

PHP代码命名规范(PHP Coding Standard) -- 精要

本文从 PHP Coding Standard 抽出最核心精要让开发小组的代码看起来很统一。
I. Names
1. Class Names
    * Use upper case letters as word separators, lower case for the rest of a word
    * First character in a name is upper case
    * No underbars ('_')
    class name : camel style, start with upper case
2. Method Names/Class Attribute Names/Method Argument Names
    * Use the similar rule as for class names. The only difference is the first letter must be lower case.
3. Variable Names
    *use all lower case letters
    * use '_' as the word separator.
4. Function Names
    * For PHP functions use the C GNU convention of all lower case letters with '_' as the word delimiter.
II. Formatting
   1. Indentation/Tabs/Space Policy
    * Indent using 2 spaces for each level.
    * Do not use tabs, use spaces. Most editors can substitute spaces for tabs.
    * Indent as much as needed, but no more. There are no arbitrary rules as to the maximum indenting level. If the indenting level is more than 4 or 5 levels you may think about factoring out code.
   2.Braces {} Policy
Traditional Unix policy of placing the initial brace on the same line as the keyword and the trailing brace inline on its own line with the keyword:

if ($condition) {   while ($condition) {
...                   ...
}                     }


III. Miscellaneous
   1. PHP Code Tags
    Use <?php ?> .
    <?php ?> is always avaliable in any system and setup.
补充:
I.文件的编码为Unix , UTF-8 without BOM
页: [1]
查看完整版本: PHP代码命名规范(PHP Coding Standard) -- 精要