PHP coding standards

By Moldovan GheorgheOn 10/27/2012
Other

Coding standards are very important in any programming language. Until now was developed all kinds of coding standard conventions by major php application communities like Zend, Symfony, Drupal and so on. But PHP as language had no any type of standard regarding coding style.

Recently PHP community made ​​a step ahead to reach a unified coding standard for PHP.

A team called PHP Framework Interoperability Group was formed by most representative men from main PHP communities, in order to elaborate a unique php coding standard, with purpose to be implemented, in future, in all major PHP frameworks and application.

Recently they are defined and approved two standards called PSR-1 and PSR-2. I think this a big step ahead in PHP programming, in order to understand better code written in PHP, and maintain PHP application by any PHP programmer.

From the PSR-1, PSR-2 proposed standards i just want to remenber couple things:

1. For intending it would be used for spaces not tabs

2. PHP script files use only UTF-8

3. Class constants MUST be declared in all upper case with underscore separators.

4. Method names MUST be declared in camelCase

5. The closing ?> tag MUST be omitted from files containing only PHP.

6. Visibility MUST be declared on all methods.

7. Method names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility.