PHP code must always be delimited by the full-form, standard PHP tags and be terminated with semicolon:
<?php
$model = $web->getModel();
$title = $model->getTitle();
?>
For single-line statements:
<?php echo $title; ?>
Indentation should consist of 4 spaces. Tabs are not allowed.
The target line length is 80 characters. However, longer lines are acceptable in some circumstances.
Strings must be concatenated using the "." operator. A space must always be added before and after the "." operator to improve readability:
<?php
$character = 'Spider' . ' ' . 'Man';
Put a space after commas in single-line statements:
<?php
$this->someMethod($first, $second, $third);
When declaring associative arrays with the Array construct, breaking the statement into multiple lines is encouraged. In this case, each successive line must be padded with white space such that both the keys and the values are aligned:
<?php
$sampleArray = array(
'firstKey' => 'firstValue',
'secondKey' => 'secondValue',
);
Within the conditional statements between the parentheses, operators must be separated by spaces for readability. The opening brace is written on the same line as the conditional statement. The closing brace is always written on its own line. Any content within the braces must be indented using four spaces.
<?php
if ($value != 2) {
$success = true;
} else {
$success = false;
}
Of course it could be replaced with:
<?php
$success = $value != 2;
But now I want to describe only code conventions.