PHP Coding standard Collation, very useful (graphic version)

Source: Internet
Author: User

There is an organization called "PHP Interoperability Framework Development Group", the main purpose of this team is to develop a variety of PHP coding specifications, the following is a few of the recommendations I compiled based on a number of common coding specifications. Psr-1:1, PHP code files must start with a <?php or <?= tag. 2. PHP code must be encoded with UTF-8 without BOM. 3, the class name must follow the large hump naming specification. (The first capital of the hump named) 4, the method name must follow the small hump naming specification. (Name of the first lowercase hump) 5. Constants in the class all letters must be capitalized, and the words should be split with _ (underscore). 6, the properties of the class can use large hump, small hump, underline division, etc., do not make mandatory norms. Prs-2:1, the code must use 4 spaces instead of a tab indent. (The advantage of using spaces instead of tab indentation is to avoid confusion when comparing code differences, patching, re-reading code, and commenting.) Also, use a space indent to make alignment easier. 2. Each line of code is recommended to be within 80 characters and must not exceed 120 characters. 3. A blank line must be inserted behind each namespace namespace declaration statement and use declaration statement block, and the use must be after namespace. 4. A pair of curly braces {} for a class must be self-formed. 5, the method of a pair of curly braces {} must be self-made line. 6. The properties and methods of the class must add access modifiers (private, public, protected), ABSTARCT and final must be declared before the access modifier, and static must be declared after the access modifier. 7, the control structure (if, while and other structure statements) must have a space after the keyword, and the calling function or method must not have. 8. The control structure ({) must be written on the same line as the Declaration, and (}) must be one line. 9. There must be no space before the left parenthesis of the control structure and the closing parenthesis. 10. All PHP files must end with a blank line. 11, the pure PHP code file must omit the last?> end tag. 12. All keywords in php must be lowercase, constant true, false, and Null must also be lowercase. 13, the parameters of the method, each parameter must be followed by a space, and must not be preceded by a space. Parameters with default values must be placed at the end of the parameter list. Finishing to find the organization's earliest PRS-1 specifications are some very basic, PHP programmers generally know, and PRS-2 is relatively specific, many senior engineers may be unconsciously used when coding, but do not write out really won't notice. Here's a standard code that I've done:

PHP Coding Specification collation, very useful (graphic version)

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.