Coding Standard

Coding Standard
  • Always remember to add single space after each comma delimiter(;)
  • Always add single space around (before and after) binary operators, concatenation operators(LIKE dot(.) etc..) are exceptional. For ex. if (a == b)
  • Use identical comparison unless you need type juggling.
  • Always use Yoda conditions when checking a variable to avoid an accidental variable values change inside the condition statement, we can also automatically check the data type.
  • Always remember to add a comma(,) after each element of array in a multi-line array include the last one.
        1 => ‘First Element’,
        2 => ‘Second Element’,
  • Add a blank line before each return statements, ignore it if the return statement is alone inside a statement-group
    if ($a === $b) {
        $c = $a + $b;
        return $c;
    if ($a === $b) {
        return true;
  • Use braces to indicate control structure body regardless of the number of statements it contains
  • Declare public methods first, then protected ones and finally private ones. The exceptions to this rule are the class constructor and the setUp() and tearDown() methods of PHPUnit tests
  • Function and it's all arguments are should be on same line, no matter how many arguments there are
  • Always use Sprinf to print Exception and error message.
Naming Conventions
  • While declaring variable, function and arguments always use camelCase, don't use underscores while declare
  • While declaring option names and parameters remember to use underscores
  • Use namespaces for all classes on top of the class
  • Abstract class should be prefix with Abstract
  • Interface should be sufix with Interface, same for traits and exceptions
  • File names should contains alphanumeric characters and underscores
  • Always write PHPDOC for all the functions/method