Home >Backend Development >PHP Problem >How to indent php code?
When writing code, you must pay attention to the indentation rules of the code. We stipulate the code indentation rules as follows:
Use 4 spaces as indentation instead of Use tab indentation (for ultraedit, you can set it in advance)
Example:
for ( $i=0;$i<$count;$i++ ){ echo "test"; }
php code writing specifications
● Code The encoding conventions in psr-1 must be followed.
●The code must be indented using 4 spaces instead of the tab key.
●The number of characters in each line should be softly kept within 80. In theory, it must not be more than 120, but there must be no hard limit.
● A blank line must be inserted after each namespace declaration statement and use declaration block.
●The opening brace ({) of a class must be written on its own line after the class declaration, and the closing brace (}) must also be written on its own line after the class body.
●The opening brace ({) of a method must be written on its own line after the function declaration, and the closing brace (}) must also be written on its own line after the function body.
●The properties and methods of the class must be added with access modifiers (private, protected and public), abstract and final must be declared before the access modifier, and static must be declared after the access modifier.
● There must be a space after the keyword of the control structure, but it must not be when calling a method or function.
● The opening brace ({) of the control structure must be written on the same line as the declaration, and the closing brace (}) must be written on its own line after the body.
● There must be no spaces after the opening left bracket and before the closing right bracket of the control structure.
The above is the detailed content of How to indent php code?. For more information, please follow other related articles on the PHP Chinese website!