- April 19, 2019
- Posted by: Skylink Technology
- Category: Web Development
Coding Standards put a crucial part in any programming language for achieving a high code quality and to write more lucid and clean code.
Here is the list of some best coding standards.
- Upgrade to the Latest Version of PHP
- Use only regular PHP Opening and closing tags, don’t utilize short tags and other php opening and closing tags.
// php code Block – php short tags
// php code Block
- Indent code appropriately.
- The closing?> tag MUST be excluded from files containing only PHP.
- PHP keywords must be in lowercase, The PHP constants true, false, and null MUST be in lower case
- Always comment your code
- Avoid unnecessary Variables (not duplicate variables pointlessly)
$name = trim($_POST[‘name’]);
Variable Naming Conventions:
- Case should never be used to distinguish between variable names. Every variable title within the current scope should be completely unique. Variable names should depict the content that they (will) contain, using either complete words or understandable abbreviations.
- Use “lowerCamelCase” style (lowercase lettering on beginning and capitalization on subsequent words) to name variable.
- Global variables should be prepended with a ‘g’.
- Global constants should be all caps with ‘_’ separators
Class Name Naming Conventions:
- Class Name Should Begin with Capitalized Letter
- Class name should only contain alphanumeric characters. Numbers are allowed in class names but are debilitated in most cases. Underscores and Capitalized letters are allowed in place of the word separator(first letter of each word)
Constant Naming Conventions:
- Constant Name should be Capitalized and we can separate each word with underscore.
Method and functions Naming Conventions:
- Method names MUST be beginning with lowercase.
- Use underscore or CaseChange methods to separate words
- C fashion comments (/* */) and standard C++ comments (//) are both fine. Utilize of Perl/shell style comments (#) is disheartened.Database
- Reduce the Number of Database Queries
There can be numerous more points which should be considered while writing your PHP program. Over all intention should be to be consistent throughout of the code and it’ll be possible only when you will follow any coding standard.