Which version of PSR is valid?

1.5k views Asked by At

Maybe I don't understand fully. I read that PSR is PHP Standard Recommendation, but there are several version of PSR, For Example autoloader use PSR-4 instead Basic Coding Standard use PSR-1

I have to follow a specific PSR version Or I have to merge the good parts of them ?

Symfony follows the standards defined in the PSR-0, PSR-1, PSR-2 and PSR-4 documents,Then each framework uses different PSR ?

2

There are 2 answers

6
Roman On BEST ANSWER

You can see the PSRs as one huge coding standard. They depend on each other but every PSR stands alone for itself. PSR-2 describes Coding Style Guide while PSR-4 describes the standard for Autoloading.

Here is a website about the PHP Standards Recommendations. You can find there a full list of all existing PSR.

PSR means PHP Standard RECOMMENDATION - so it is only a recommendation on how to handle/format a specific part of a php-application. The index is just a ID to identify what the psr is good for. Do not understand it as a version-number. PSR-0 and PSR-4 both cover the handling of Autoloader.

0
Alexander van Oostenrijk On

The PHP Standard Recommendation is about how you should write your code so that it’ll be easily readable and usable by others. It covers topics like coding style, file organization, autoloading and standardizes various interfaces. The PSR was thought up by the Framework Interoperability Group (FIG), which came into being at the php|tek 2009 conference. Its members include the authors of various well-known PHP frameworks. The PSR is in no way “official”; it’s just that the Framework Interoperability Group (FIG) contains a nice cross-section of experienced PHP developers, who vote on whatever the best coding style should be. As such, you can follow all or part of PSR, or none of it. It’s up to you really, but some projects that you want to contribute to may require that you follow some of the PSR, just so that everyone is on the same page. There’s nothing wrong with having a standard where there wasn’t one before.

So who’s a member? There are over 20 members now (from 5 when they started), and they include the authors of CakePHP, Composer, Zend, Lithium, SugarCRM and Symphony. People who’ve been around the PHP block, so to speak.

As for the PSR standards themselves, there are about 17 of them, but only 7 have been accepted by all members. The rest are still being voted on, or have draft status [as of September 2016].

(I wrote this article which looks at PSR-1 in detail as an example.)