Coding standard - sifatanwar-1812887642/cse299 GitHub Wiki

Php coding standard

Introduction:

  • Coding standards are the set of guidelines defined for a specific language that recommend style, practices to be followed for each piece of code in a programming language.
  • Normally it includes guidelines for naming conventions for variables, formatting and indentations, comments, file naming etc.

Guidelines for coding standards:

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.

Comments

  • For documentation comments we will use (/* /) format.
    Otherwise comment will be given by / ....*/

Spacing:

  • Place a space between operators, assigments ("=") and their operands.>

example:

  • $x = ($a + $b) * $c / $d + foo();

File Naming Conventions:

  • All file names must be all lower case. No exceptions.

Class name:

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

For example:

Class UserCustomer:

{

}

Variables name:

  • Variable names should be concise and contain only lower-case letters and underscores between two word .
  • Loop iterators should short, preferably a single character.

For example:

$first_name

$Last_name

For($i=0; $i<$max;$i++)

Control Structures:

  • The structure keyboards such as if, for, for each, while, switch should be followed by a space as should parameter/argument lists and values.
  • Braces should be places on a new line, and break should have the same tab as its case.

For example:

If($arg==true)
{
//do something
}
Elseif($arg===null)

{

//do something else here

}

Else

{

//catch all do something

Here

}

For($i=0;$i<$max;$i++)

{

//loop here

}

Switch($var)

{

Case ‘value1’:

//do something here break;

Default:

//do something here

Break;