PHP Code Style
If you use a third-party framework and have a code-style description, follow its code-style standard, otherwise!
= = Format:
* Using UTF-8 encoding
* Use 4 spaces to indent, disable tab
* Unix style line break (LF)
* Use spaces in comma, colon, and semicolon operators
* Do not use spaces in front (, [Back,],)
* Use 4 spaces to indent in a code block
* Using level Indentation
* Use a blank line before the return value of the return method (unless there is only one line of code) and use blank lines in two methods to differentiate
* Use blank line distinction between two large logical sections of code
* Keep line words within 80 words, up to 120
* Use standard PHP tag delimitation to prohibit the use of short tags ( ), for text that contains only PHP code
The PHP End flag ("?>"), the end of the file is annotated with a note "/* End of the */"
* A single line of code must also end with a semicolon (;)
= = Name:
* File name using Snake_case method, prohibit the use of bloated file name
* variable names are used Snake_case to prohibit the use of bloated variable names
* Prohibit use of single characters as local variables (such as $i), except in the For loop
* Prohibit use of uppercase as global variables, such as using uppercase letters, should use Screaming_snake_case
* Class name using CamelCase mode, method name using CamelCase mode (keep uppercase like http,rfc,xml abbreviation)
* Constant Name using Screaming_snake_case method
badsuperclass.phpsuperclass.phpsuperclass.php$i = "Foobar"; Single-character variables are only allowed to be used in the For loop $bufferdtext //Hump variables, and the meaning can be reduced by a few $groupid//two words need to be underlined between $name_of_last_city_used// Too long myconstant //should be underlined and the letters are not all uppercase n //single-character s_c_ver //meaning unclear class Superclassclass superclassfunction FileProperties ()//meaning unclear and no hump-named function fileproperties ()//meaning unclear function getfileproperties ()//better, but no hump-named// Goodsuper_class.phpfor ($i = 0; $i < $i + +) $buffer $group_id$last_citymy_constantnewlinesuper_class_versionclass Superclassfunction getfileproperties ()
= = Syntax:
For PHP code embedded in HTML, for code blocks like if, for, foreach, and while, with if: ... endif; For: ... endfor; foreach: Endforeach; and while: ... endwhile; method block
...
isLoggedIn ())://checking logged in?>
...
= = Comment:
* Document block must be compatible with phpdocumentor format, please refer to: http://phpdoc.org/
* Avoid unnecessary opinions.
/** * Controller Class Description Info */class controller { private static $instance; Public function __construct () { ... } /** * Function Description Information * /public static function &get_instance () { ... } /* End of File controller.php */
= = Other:
* Keep the code simple
* Maintain consistency
Reference: Codeigniter,zendframework,wordpress, etc.
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
other
Github Https://github.com/styleguide
HTML/CSS Code Style (US)
Http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml
Javascript Code Style (US)
Http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
Ruby style See (English) Https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE
1/F huawei2772 2012-02-17
Good!