PHP Guidelines

PHP Coding Recommendations


What is PHP Guidelines?

These recommendations are exactly the same as PHP-FIG PSR-0, 1, 2 and PSR-4 standards, with two differences:

  • you MAY use tabs for indenting
  • you MAY write PHP constants TRUE, FALSE, and NULL in upper case

Basically, our standards are suitable for all PHP developers who want to be compliant with well-known standards from the PHP-FIG, but are not interested in whitespace holy wars.


Rationale

Some people like tabs, some like spaces. The 30 % of PHP projects use tabs (including some PHP-FIG member projects). We respect freedom of choice, especially when unsignificant whitespace can be converted automatically, for example using Git:

git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only'
git config --global filter.tabspace.clean 'expand --tabs=4 --initial'

(You should also configure Git to convert line endings.)

Once chosen indentation is difficult to change, especially in bigger projects, because such change will make it harder to deal with Git history, rebasing existing branches and pull requests, etc.

Therefore standard PGS-2 in comparsion to the PSR-2 allows using tabs for indentation.

Whole PHP documentation uses constants TRUE, FALSE and NULL written in upper case. PSR-1 itself states that class constants MUST be in upper case. Therefore PGS-2 allows in comparsion to the PSR-2 to write them in upper case too.


Using tabs or capital letters is matter of your choice. But you MUST use the same style consistently across all files in whole vendor namespace.


Member Projects

View Our Github Page.