title | updated | permalink |
---|---|---|
How to Write Standardized PHP Code? |
October 9, 2016 |
/faq/coding-standards/ |
For PHP, there are many standards and coding style recommendations that you should look into when writing code. It simplifies collaboration on code and makes it more readable once you get used to a particular style.
One of the most adopted standards recommendations in PHP is PHP FIG, which recommends coding style via two of its PSRs (PHP Standard Recommendation):
Many open source projects also extend the above PSRs with their own coding style guides, for example:
Many advanced PHP IDEs and editors also offer code refactoring via plugins and extensions. With predefined common coding styles such as PSR-1 and PSR-2, with refactoring code, automatic code generation, autocomplete and similar things, consistently writing standardized PHP code can be done with ease.
The more you write code, the more you will understand the importance in using common style guides. Especially when working with source code control (eg, Git, coworkers), or just to be consistent in general.
- Core PHP language specification
- PHP_CodeSniffer - Tokenizes PHP, JavaScript and CSS files, and detects violations of a defined set of coding standards.
- PHP Coding Standards Fixer - A tool that fixes coding standards in your code.
- PHP-FIG: Extended Coding Style Guide proposal