The different coding standards for Php

In team development, setting a code standard is very important. According to the one code standard, the code is clear and easy to read, and it is also easy to see the difference in your code when you test it. Sadly, PHP coding standards are different from the PHP version and frameworks. For example, names of methods should be written in different styles like camelCase, snake case etc. There are also different rules for naming namespaces and classes and how to use indents and spaces. We will introduce several popular PHP standards in this article.

PSR-2 basic coding standard

PHP Framework Interop Group (PSR) is a PHP-FIG standard. PHP does have different implementations and libraries, including Zend Framework and Symfony, but they all differ slightly. PHP-FIG has therefore established a coding standard for all PHP-frameworks which include members from each framework...PSR. PSR consists of several standards, such as PSR-1, PSR-2 and PSR-4. The autoloaders are PSR-0 and PSR-4 codings and the coding specifications are PSR-1 and PSR-2. The PSR-2 coding standard is currently the most common for PHP.

PSR-1 basic coding standard

The default functions of PHP are set in snake case, but the method names of PSR-1 in camelCase must be defined. There are no specific rules for variable and property names, so you can use any style you want but they should be consistent. There are no specific rules. For instance, define normal CamelCase properties and static Upper CamelCase properties.

Why PSR-0 and PSR-4

For PHP5 namespaces have been introduced. In previous PHP versions, namespaces do not exist. There was an issue where class names sometimes clash when no namespaces are present. If you had another class specified by that name in one of your imported libraries, you could not, for instance, define a class called ' Mysql. PSR-0 is a standard for the use of older codes in this way. Even if it is inexpensive, PSR-0 could be more suited than PSR-4 if old php programming is used. Nonetheless, for new projects it is best to use PSR-4.

Web application on simpli-web.com last news.

Web application