PHP Basic code Standard Guideline
PHP Basic code Standard Guideline:
Type of Guideline | Guideline Description |
---|---|
Start PHP tag | All PHP code must be started with |
Close PHP tag | Closing of PHP tag (?>) should be omitted from script which contain only PHP code. |
Encoding | All PHP files must use only UTF-8 encoding |
Class Naming Convention | All class name must be declared in StudlyCaps |
Class Constant Naming Convention | Class Constants must be declared in UPPERCASE only with underscore. |
Class Method Naming Convention | Method name must be declared in camelCase |
Keyword Naming Convention | All PHP constants true, false, and null MUST be in lower case |
Code Indentation | Code should use 4 spaces for indentation instead of using tabs directly. |
Character limit for per Line of code | Its always preferable to not use any line limit after certain length. But code lines should be 80 character only or less than that. |
Opening and Closing Braces | Each opening and Closing braces for each class and method should go to new line only. |
Method Visibility | Visibility must be declared for all properties and methods. Abstract and Final must be written before visibility. Whereas static should come after visibility. |
Uses of space under control keyword (like if,else,switch) | Control Structure keyword must have one space after them. The same apply for for, while, switch, try, catch as well. Although the same doesn’t apply for function call. |
Opening Closing Braces for Control Structure | Opening braces should go on same line of control structure. Closing braces should go to next line of body. |
Space after parenthesis for Control Structure | There must not be any space after opening or closing parenthesis in any control structure. |
Spacing between Method Argument | There must be one space after each comma |
Space after assigner | All variables should have a space separating the assigner |
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments