PHP Coding Standards (


Always use to delimit PHP code, not the <? ?> shorthand.

 <?php ?> 

Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.

if (true) { 
   switch (condition) { 
      case 1: 
      case 2: 

You are strongly encouraged to always use curly braces even in situations where they are technically optional.

if (true) { 
   // single line stuff 

Split long if statements onto several lines keeping the question mark and the colon at the front.

if (($condition1 || $condition2) 
    && $condition3 && $condition4 
   ) { 
   //code here 

There should be one space on either side of an equals sign used to assign the return value of a function to a variable

$long_variable = foo($baz); 

The CS require lines to have a maximum length of 80 chars. It is allowed to split parameters in function calls onto several lines.

   $parameterOne, $parameterTwo, $aVeryLongParameterThree

The same applies not only for parameter variables, but also for nested function calls and for arrays.

      "foo" => "bar" 

To support readability, the equal signs may be aligned in block-related assignments:

$short     = foo($bar); 
$thelonger = foo($baz);


Class and function declarations have their opening brace on a new line:

class Foo_Bar 
function doThing() 

Function declarations follow the “K&R style”

Arguments with default values go at the end of the argument list.

function doAnotherThing($id = 0, $doAgain = false) 

include_once and require_once are statements, not functions. Parentheses should not surround the subject filename.

include_once "/file.php";