- Use UTF-8 without BOM
- Use tabs for indenting and spaces for aligning. Details…
- No limit on line length. The soft limit is 120 characters. Lines SHOULD be 80 characters or less.
- No whitespace at the end of lines (except special meanings like in markdown or email)
- Always add a new line to the end of files (better for git)
Follow the standards defined in PSR-0, PSR-1 and PSR-2 except the following points:
- Code MUST use tabs for indenting and spaces for aligning. Details…
else
andelseif
MUST be on the next line after the closing parenthesis- To check if a value is empty or falsy use
$var
or!$var
if the variable definitely exists, otherwise useempty($var)
or!empty($var)
- Always use
===
and!==
for string comparison - Ommit the semicolon for single expressions in php templates (e.g.
<?php echo $var ?>
instead of<?php echo $var; ?>
) - The last item of an multiline array must end with a comma
- In PHP 5.4
<?= $var ?>
should be used instead of<?php echo $var ?>
- In PHP 5.4
[1, 2, 3]
should be used instead ofarray(1, 2, 3)
- php.php standard PHP code
- php-template.php PHP code used in a template
- php-wordpress.php PHP code in WordPress themes follows the WordPress Coding Standards
- php-wordpress-template.php PHP code used in a WordPress template
- HTML5
- Write everything in XHTML syntax except self closing tags and boolean attributes (
<input checked>
instead of<input checked="checked" />
) - Close all tags, except self closing tags as shown above
Recommended settings:
{
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"trim_trailing_white_space_on_save": true,
"open_files_in_new_window": false,
"rulers": [80, 120]
}