anchor |
---|
code_style_guide |
The PHP community is large and diverse, composed of innumerable libraries, frameworks, and components. It is common for PHP developers to choose several of these and combine them into a single project. It is important that PHP code adhere (as close as possible) to a common code style to make it easy for developers to mix and match various libraries for their projects.
The Framework Interop Group has proposed and approved a series of style recommendations. Not all of them related to code-style, but those that do are PSR-0, PSR-1, PSR-2 and PSR-4. These recommendations are merely a set of rules that some projects like Drupal, Zend, Symfony, CakePHP, phpBB, AWS SDK, FuelPHP, Lithium, etc are starting to adopt. You can use them for your own projects, or continue to use your own personal style.
Ideally you should write PHP code that adheres to a known standard. This could be any combination of PSR's, or one of the coding standards made by PEAR or Zend. This means other developers can easily read and work with your code, and applications that implement the components can have consistency even when working with lots of third-party code.
- Read about PSR-0
- Read about PSR-1
- Read about PSR-2
- Read about PSR-4
- Read about PEAR Coding Standards
- Read about Zend Coding Standards
- Read about Symfony Coding Standards
You can use PHP_CodeSniffer to check code against any one of these recommendations, and plugins for text editors like Sublime Text 2 to be given real time feedback.
Use Fabien Potencier's PHP Coding Standards Fixer to automatically modify your code syntax so that it conforms to these standards, saving you from fixing each problem by hand.
English is preferred for all symbol names and code infrastructure. Comments may be written in any language easily readable by all current and future parties who may be working on the codebase.