PHP variable naming


Variable naming is divided into naming rules for ordinary variables, static variables, local variables, global variables, Session variables, etc.

1) Ordinary variables
Ordinary variable naming follows the following rules:
a. All letters are lowercase;
b. For a variable using multiple words, use '_' as the interval between each word.
For example: $base_dir, $red_rose_price, etc.

2) Static variables
Static variable naming follows the following rules:
a. Static variables start with lowercase s_;
b. All letters in static variables are lowercase;
c. Variable names composed of multiple words use '_' as the interval between each word.
Examples: $s_base_dir, $s_red_rose_prise, etc.

3) Local variables
Local variable naming follows the following rules:
a. Use lowercase letters for all letters;
b. Variables start with '_';
c. Local variable names composed of multiple words use '_' as the interval between each word.
Examples: $_base_dir, $_red_rose_price, etc.

4) Global variables
Global variables should be prefixed with 'g'. It is very important to know the scope of a variable.
For example

global $gLOG_LEVEL;
global $gLOG_PATH;

5) Global constants
Global variable naming follows the following rules:
a. Use all capital letters
b. Use '_' as a separator between multiple words in global variables.
Examples: $BASE_DIR, $RED_ROSE_PRICE, etc.

6) Session variables
Session variable naming follows the following rules:
a. Use all capital letters;
b. The session variable name starts with 'S_';
c. Use '_' space between multiple words.
Examples: $S_BASE_DIR, $S_RED_ROSE_PRICE, etc.