PSRs are PHP Standards Recommendations. They are a standard and clearly defined way to do many common tasks.
It comprises what should be considered the standard coding elements that are required to ensure a high level of technical interoperability between shared PHP code
It considers PSR-1 and it is intended to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code.
namespace ...
should be on its own line?>
must not be present, for files containing only PHPtrue
, false
, null
) must always be in lower caseextends
and implements
must be on the same line as the class namepublic
/protected
/private
for all object properties. Same for methods.It describes a common interface for logging libraries
It describes a specification for autoloading classes from file paths. <NamespaceName>(<SubNamespaceNames>)*<ClassName>
PSR-4 is often used with Composer's composer.json
to help with autoloading of PHP classes.
{ "autoload": { "psr-4": {"": "src/"} } }
The main purpose of this PSR is to provide a complete and formal definition of the PHPDoc standard.
The goal of this PSR is to allow developers to create cache-aware libraries that can be integrated into existing frameworks and systems without the need for custom development
It describes common interfaces for representing HTTP messages as described in RFC 7230 and RFC 7231 The PSR-7 bridge converts HttpFoundation objects from and to objects implementing HTTP message interfaces defined by the PSR-7. Better just use HTTP foundation
It describes a common interface for dependency injection containers. The goal is to standardize how frameworks and libraries make use of a container to obtain objects and parameters (called entries in the rest of this document)
It describes common interfaces for representing a hypermedia link
It describes common interfaces for dispatching and handling events
It describes common interfaces for HTTP server request handlers and HTTP server middleware components that use HTTP messages
It describes a simple yet extensible interface for a cache item and a cache drive
It describes a common standard for factories that create PSR-7 compliant HTTP objects.
It describes a common interface for sending HTTP requests and receiving HTTP responses
PHPCS Fixer (sensiolabs): By default the PSR1 and PSR2 rules are used. Also you can use rule: @Symfony
The PHP.net wiki: To track internal development of PHP Before features can be added to PHP or before any breaking changes can occur, the change must first go through the Request for Comments (RFC) process.
Symfony project implements lots of PHP-FIG PSR standards, such as PSR-2 (code styling), PSR-3 (Logger interface), PSR-4 (autoloader), PSR-6 (caching interface) and PSR-16 (simple cache).
And also: PSR-11
PSR-11 defines a simple API that service containers must implement. In practice, this standard won't impact your existing Symfony applications. For starters, the public API only defines two methods called get()
and has()
which are named and behave in the same way as the Symfony methods that you know and use.