PHP coding standards

Indenting and Line Length

Use an indent of 4 spaces, with no tabs. This helps to avoid problems with diffs, patches, SVN history and annotations.
It is recommended to keep lines at approximately 75-85 characters long for better code readability.

Control Structures

These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them:
<?php
if ((condition1) || (condition2)) {
     action1;
} elseif ((condition3) && (condition4)) {
     action2;
} else {
     defaultaction;
}
?>
Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls.

You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.
For switch statements:
<?php
switch (condition) {
case 1:
     action1;
     break;

case 2:
     action2;
     break;

default:
     defaultaction;
     break;
}
?>

Split long if statements onto several lines

Long if statements may be split onto several lines when the character/line limit would be exceeded. The conditions have to be positioned onto the following line, and indented 4 characters. The logical operators (&&, ||, etc.) should be at the beginning of the line to make it easier to comment (and exclude) the condition. The closing parenthesis and opening brace get their own line at the end of the conditions.
Keeping the operators at the beginning of the line has two advantages: It is trivial to comment out a particular line during development while keeping syntactically correct code (except of course the first line). Further is the logic kept at the front where it's not forgotten. Scanning such conditions is very easy since they are aligned below each other.
<?php

if (($condition1
     || $condition2)
     && $condition3
     && $condition4
) {
     //code here
}
?>
The first condition may be aligned to the others.
<?php

if (   $condition1
     || $condition2
     || $condition3
) {
     //code here
}
?>
The best case is of course when the line does not need to be split. When the if clause is really long enough to be split, it might be better to simplify it. In such cases, you could express conditions as variables an compare them in the if() condition. This has the benefit of "naming" and splitting the condition sets into smaller, better understandable chunks:
<?php

$is_foo = ($condition1 || $condition2);
$is_bar = ($condition3 && $condtion4);
if ($is_foo && $is_bar) {
     // ....
}
?>

Function Calls

Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Here's an example:
<?php
$var = foo($bar, $baz, $quux);
?>
As displayed above, there should be one space on either side of an equals sign used to assign the return value of a function to a variable. In the case of a block of related assignments, more space may be inserted to promote readability:
<?php
$short         = foo($bar);
$long_variable = foo($baz);
?>
To support readability, parameters in subsequent calls to the same function/method may be aligned by parameter name:
<?php

$this->callSomeFunction('param1',     'second',        true);
$this->callSomeFunction('parameter2', 'third',         false);
$this->callSomeFunction('3',          'verrrrrrylong', true);
?>

Class Definitions

Class declarations have their opening brace on a new line:
<?php
class Foo_Bar
{

     //... code goes here

}
?>

Function Definitions

Function declarations follow the "K&R style":
<?php
function fooFunction($arg1, $arg2 = '')
{
     if (condition) {
         statement;
     }
     return $val;
}
?>
Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Here is a slightly longer example:
<?php
function connect(&$dsn, $persistent = false)
{
     if (is_array($dsn)) {
         $dsninfo = &$dsn;
     } else {
         $dsninfo = DB::parseDSN($dsn);
     }

     if (!$dsninfo || !$dsninfo['phptype']) {
         return $this->raiseError();
     }

     return true;
}
?>

Arrays

Assignments in arrays may be aligned. When splitting array definitions onto several lines, the last value may also have a trailing comma. This is valid PHP syntax and helps to keep code diffs minimal:
<?php

$some_array = array(
     'foo'  => 'bar',
     'spam' => 'ham',
);
?>

Comments

Complete inline documentation comment blocks (docblocks) must be provided.
Non-documentation comments are strongly encouraged. A general rule of thumb is that if you look at a section of code and think "Wow, I don't want to try and describe that", you need to comment it before you forget how it works.
C style comments (/* */) and standard C++ comments (//) are both fine. Use of Perl/shell style comments (#) is discouraged.

PHP Code Tags

Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups.

Naming Conventions

 

Classes

Classes should be given descriptive names. Avoid using abbreviations where possible. Class names should always begin with an uppercase letter. Examples of good class names are:
Log Net_Finger HTML_Upload_Error

Class Variables and Methods

Class variables (a.k.a properties) and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Some examples (these would be "public" members):
$counter connect() getData() buildSomeWidget()
Private class members are preceded by a single underscore. For example:
$_status _sort() _initTree()
The following applies to PHP5.
Protected class members are not preceded by a single underscore. For example:
protected $somevar protected function initTree()

Constants

Constants should always be all-uppercase, with underscores to separate words. Prefix constant names with the uppercased name of the class/package they are used in. Some examples:
DB_DATASOURCENAME SERVICES_AMAZON_S3_LICENSEKEY