6. Coding Standards - shadman-1/Online-Mobile-Store GitHub Wiki

Closing PHP tag:

• Files containing only PHP code should always omit the closing PHP tag (?>). This prevents many of the elusive white screens of death.

File naming conventions:

• All file names must be lower case.

Class name:

• Class names should use underscores to separate words and each word in the class name should begin with a capital letter.

  Example:          Class Employee_manager
                       {
                          
                        }

Method names: • Like class names, method names should use underscores to separate words. • Method names should be all lower case. Example: Class Employee_manager { Public function get_data($name,$data) { //some code here } }

Variables name:

• Variable names should be concise and contain only lowercase letters and underscores. Example: $first_name $last_name • Loop iterators should be short, preferably a single character.

  Example:   for ($i=0; $i<$max; $i++)

Control Structures:

• The structure keywords such as if, for, foreach, while, should be followed by a space as should parameter/argument lists and values. • Braces should be placed on a new line, and break

   Example:    if ($arg === true)
               {
                   //do something here
               }
               else if ($arg ===null)
               { 
                  //do something else here
                }
                else
               {
                   //catch all do something
                here
                        }
   
    Example:  for ($i = 0; $i < $max; $i++)
                       {
                              //loop here
                       }

Comments:

A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code.

Example: Single-line comment:[ // ]

Example: Multiple-line comments:[ /* */ ]