Home >Backend Development >PHP Tutorial >Notes on PHP naming format (detailed explanation)

Notes on PHP naming format (detailed explanation)

烟雨青岚
烟雨青岚forward
2020-06-08 17:58:512701browse

Notes on PHP naming format (detailed explanation)php naming format considerations

When writing PHP code, you must always maintain naming conventions. Firstly, it is easy to check for errors. Secondly, it is convenient for others. Watch. This article introduces in detail the considerations for various naming formats.

1. Class naming

(1) Use uppercase letters as word separators, and use lowercase letters for other letters.

(2) The first letter of the name should be capitalized.

(3) Do not use underscore ("_").

Such as: Student, People, Animal

2. Class attribute naming

(1) The attribute naming should start with the character "m" as prefix.

(2) The prefix "m" follows the same rules as the class naming.

Such as: mValue, mString, etc.

3. Method naming

The function of a method is to perform an action and achieve a goal. So the name of the method should describe what the method does. Generally, the prefixes and suffixes of names have certain rules, for example, Is (judgment), Get (get), Set (set). The naming specifications of methods are consistent with class naming.

4. Naming parameters in the method

(1) Use lowercase letters for the first character.

(2) All characters after the first character are capitalized according to the class naming rules.

5. Variable naming

(1) All letters should be lowercase.

(2) Use "_" as the delimiter of each word. Such as: $msg_error, class_name, etc.

6. Reference variables/function naming

(1) Reference variables/naming must be prefixed with "r".

7. Global variables

(1) Global variables should be prefixed with "g". For example: global= $a, global= $b

8. Constant/global constant

(1) Constant/global constant, should be all Use capital letters and separate words with "_". Such as:

define(DEFAULT_NUM_AVE’,9)
define("DEFAULT_NUM_SUM’,500)

9. Static variables

(1) Static variables should be prefixed with "s". For example:

 static $sStatus = 1;

10. Function naming

(1) All letters in the function name are lowercase letters, and multiple words are represented by "_" segmentation.

Thank you for reading. I hope you can follow the naming convention after reading so that you can learn better in the future.

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of Notes on PHP naming format (detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete