Specification for naming of PHP files, naming of classes and methods, naming of variables, etc.

Source: Internet
Author: User
Tags uppercase letter
The specification of names of PHP files, classes and methods, and the naming of variables is especially important when naming.

1. File naming

The name of the class file must begin with an uppercase letter, and the names of other files (profiles, views, generic script files, etc.) are all lowercase.

some_library.php application_config.php

2. Naming classes and methods

The class name must start with an uppercase letter, use an underscore between multiple words, and do not use the Hump naming method.

Class Super_class

The method of the class should use all lowercase, and should clearly indicate the function of the method, preferably including a verb. Avoid using lengthy names, and use underscores to split between multiple words.

function Get_file_properties ()

3. Naming of variables

The naming conventions for variables are very close to the naming conventions of class methods, use all lowercase, use underscores to split, and should explicitly indicate the purpose of the variable. A very short meaningless variable should only be used as an iterator in the for loop.

for ($j = 0; $j < $j + +) $last _city

Constants follow variable names, but all uppercase letters

My_constantnewline

Notice that the variable is assigned a blank space before and after the value

The keywords 4.TRUE, FALSE, and NULL all use uppercase.

5. Do not use | | operator, which is not visible on some devices (which may look like a number 11), using the && operator is a bit better than using and, but both are acceptable. In addition, in! You should add a space before and after the operator.

Note: Some PHP functions return false on failure, but may also return a valid value such as "" or 0, which are equal when the loose type is compared and false. So when you use these return values for comparison in conditions, be sure to use strict type comparisons to ensure that the return value is really what you want, not the other values of the loose type.

You should also follow this rigorous approach when checking your own return values and variables, using = = = and!== when necessary.

6. Indent with Tab instead of space

7. Strings are enclosed in single quotation marks, use double quotation marks when there are variables in the string, and wrap the variables with curly braces. In addition, double quotation marks should be used when there are single quotes in the string, so you do not use escape characters.

' My string ' "My string {$foo}" "Select Foo from bar WHERE baz = ' bag '"

This article explains the PHP file naming, class and method naming, variable naming and other specifications, more relevant content please focus on PHP Chinese web.

Related Article

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.