PHP Standards Recommendations (PSR)

As technology usage increases, everyone develops their own way of using it. This leads to difficulties in maintaining consistency and interoperability.

Example:
Developers follow different naming conventions and coding styles. For instance, method names may be written in various styles like camelCase, snake_case, etc.

These inconsistencies make it challenging to work across different frameworks and PHP versions as well.

With the growing adoption of PHP and the emergence of new frameworks, the need for a standardized set of rules became evident.

Why is Standardization in PHP Necessary?

Standardization in PHP helps achieve:

  • Interoperability of components across different frameworks and projects.
  • Consistent and readable code, making it easier to maintain.
  • A common technical foundation for implementing best practices in programming and testing.

To address these concerns, the PHP Framework Interoperability Group (PHP-FIG) was formed, consisting of several PHP framework founders. This initiative led to the creation of PHP Standards Recommendations (PSR)—a set of standardized guidelines for PHP, similar to Java Specification Requests (JSR) in Java.

Key PSR Standards

Among the various PSRs, seven have been widely accepted by all members:

PSR-0 – Autoloading Standard

  • Defines the mandatory requirements for autoloader interoperability.
  • Deprecated: PSR-0 is no longer in use; you should use PSR-4 instead.

PSR-1 – Basic Coding Standard

  • Establishes fundamental coding rules to ensure high interoperability between shared PHP code.

PSR-2 – Coding Style Guide

Defines coding style conventions, such as PHP keywords (true, false, null) must always be in lowercase. Extends and implements must be on the same line as the class name.

PSR

Resource

Leave a Comment