PHP code style

Source: Internet
Author: User
Tags php foreach
If the PHP code style uses a third-party framework and provides code style instructions, it complies with the code style standard. Otherwise, the following code is displayed! Format: * use UTF-8 encoding * use 4 spaces indent, do not use Tab * Unix style line break (LF) * use space in comma, colon, and semicolon operators * in (, [Later,],) do not use spaces * use four spaces in the code block to indent * use hierarchical indentation * return value in the return method PHP code style
If a third-party framework is used and a code style description is provided, the code style standards are followed; otherwise, the following code is displayed!

= Format:

* Encoding with UTF-8

* Four spaces are used for indentation. Tab is not allowed.

* Unix style line break (LF)

* Use spaces in the comma, colon, and semicolon operators

* No space is used before (, [,],).

* Use four spaces to indent a code block

* Hierarchical indentation

* Use a blank line before the return value of the return method (unless there is only one line of code) and use a blank line to distinguish between the two methods.

* Use empty lines to distinguish between two large logical code segments

* Keep the number of words in a row to less than 80 characters, and the maximum number of words in a row to 120

* Use Standard PHP tag demarcation. do not use short tags ( ).
PHP end sign ("?> "), Note the End of the file"/* End of file */"

* The single-line code must also end with a semicolon (;).

= Name:

* The file name must be in the "snail ke_case" mode. do not use a bloated file name.

* The variable name is in the "snail ke_case" mode. do not use a bloated variable name.
* Do not use a single character as a local variable (for example, $ I), except in a for loop.
* Do not use uppercase letters as global variables. for example, use the screaming_snke_case method.

* The class name uses the CamelCase method, and the method name uses the camelCase method (keep the uppercase characters such as HTTP, RFC, and XML acronyms)

* The constant name uses the screaming_snke_case method.

// Badsuperclass. phpSuperClass. phpsuperClass. php $ I = "foobar"; // single-character variables can only be used in a for loop $ bufferdText // camper variable, and the meaning can be simplified. $ groupid // The two words must be separated by underlines. $ name_of_last_city_used // too long MyConstant // should be underlined and the letters are not all uppercase N // Single character S_C_VER/ /The meaning is unclear. class superclassclass superClassfunction fileproperties () // the name of function fileProperties () is not clear and the name of function fileProperties () does not exist. // The name of function getfileproperties () is better, however, there is no camper name // goodsuper_class.phpfor ($ I = 0; $ I <10; $ I ++) $ buffer $ group_id $ last_cityMY_CONSTANTNEWLINESUPER_CLASS_VERSIONclass SuperClassfunction getFileProperties ()


= Syntax:

For PHP code embedded in HTML, for code blocks such as if, for, foreach, and while, if :... endif; :... endfor; foreach :... endforeach; and while :... endwhile; Method block

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


= Note:

* The document block must be compatible with the phpDocumentor format, see: http://phpdoc.org/

* Avoid unnecessary comments

/*** Controller class description information */class Controller {private static $ instance; public function _ construct (){...} /*** function description */public static function & get_instance (){...} /* End of file controller. php */


= Others:

* Keep the code simple

* Maintain consistency


Refer to: 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

Others
Github https://github.com/styleguide.
HTML/CSS code style (English)
Http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml
Javascript code style (English)
Http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
Ruby style see https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE

1st floor wei2772 2012-02-17

Good!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.