Coding Standard - jubairzaman/E-repair GitHub Wiki

Coding Standards: (PHP) Naming Conventions: Variable Name: • A variable starts with the $ sign, followed by the name of the variable • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive

Example: $price $_name $_POST $_post PHP Code Tags:

to delimit PHP code, not the ?> shorthand. This is required for PHP compliance and is also the most portable way to include PHP code on differing operating systems and setups.

Examples

Function Name: • Function declarations follow the "BSD/Allman style" −

Example: function fooFunction($arg1, $arg2 = '') { if (condition) { statement; } return $val; } Function Call: Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Example: $var = foo($bar, $baz, $quux); Exception Names: The throw statement allows a user defined function or method to throw an exception. When an exception is thrown, the code following it will not be executed. If an exception is not caught, a fatal error will occur with an "Uncaught Exception" message.

Indentation: Use an indent of 4 spaces and don't use any tab because different computers use different setting for tab. It is recommended to keep lines at approximately 75-85 characters long for better code readability. Control Structures − These include if, for, while, switch, etc. Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls. You are strongly encouraged to always use curly braces even in situations where they are technically optional.

Example: if ((condition1) || (condition2)) { ….action1; }else ((condition3) && (condition4)) { ….action2

⚠️ **GitHub.com Fallback** ⚠️