What does PSR mean?

Asked

Viewed 37,795 times

9

Hello folks I recently found a term called PSR in the PHP area, but the topic was not very enlightening in defining the real meaning of the word PSR, I saw that it was related to the Object Orientation area, I did a google search and did not find much, I believe I searched for the wrong terms.

But finally, someone could explain to me the meaning of PSR and its real application?

  • 2

    Sure it’s SRP? It’s not SRP PSR ?

  • 1

    really edited question

  • 4

    LOL I thought it was about single responsibility principle.

  • Related: http://answall.com/questions/128330/psr-7-e-a-immutability

  • See this guide: Introduction to PSR-1. Explains what PSR is.

2 answers

17


The PSR (in English PHP Standards Recommendation) are project specifications proposed by PHP-FIG (PHP Framework Interop Group), a group composed of representatives of expressive PHP projects.

These standards aim to facilitate code reuse among the various projects that implement a certain standard.

An example is the PSR-3, which suggests a specification for Application Log Interface. Any project that supports PSR-3 can simply replace the log module with another compatible one that also supports PSR-3 without any impact on the original design (Ai we have the idea of interoperability between projects).

In addition to the standard Logs, there are Psrs for implementations of autoload (PSR-0 and PSR-4), code style suggestions, such as key position, indentation (Use tabs or spaces?) (PSR-1 and PSR-2).

There are also draft proposals for standardization of docblock documentation (PSR-5) and an interface for HTTP requests (PSR-7)

More information read the FAQ and visit the repository on Github standards already accepted by the group.


It is important to remember that the adoption of these standards in your project is optional.

No one is required to implement "X" functionality in a certain way, but it is recommended to implement from a standard already known and adopted by the community not to cause future headaches with your code.

  • Now it killed my curiosity! : ) Neither the site with the PSR explains what the acronym means! (or I who did not see?)

  • @bfavaretto with his comment I was in doubt about the real meaning :) I’ll ask on irc to see if that’s right.

  • 1

    that’s right...

  • Thanks for the double check

  • 1

    Fyi: will include in the FAQ the meaning: https://github.com/php-fig/php-fig.github.com/pull/120

  • So basically, PSR are interfaces that should be implemented by the classes in my application? I should use the same proposed names (for classes, functions, ...) or use whatever I want?

  • 1

    @Guilhermecostamilam are some ready-made interfaces, which you can include in your project via Composer https://packagist.org/packages/psr/ ... others are code style recommendations, docblocks, etc

Show 2 more comments

8

I found an answer:

PHP Framework Interoperability Group is a group of voting members who represent PHP frameworks and non-voting members who can participate and who have defined, so far, three standards: PSR-0, PSR-1 and PSR-2.

The PSR-0 standard, referred to as the autoloader. The PSR-1, the basic coding standard and the PSR-2, goes beyond the basic standardization of the PSR-1.

How to access the PSR style guide

Via URL, via

PSR-0: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
PSR-1: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
PST-2: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

Via Git, I recommend

git clone git://github.com/php-fig/fig-standards.git
  • No need to clone, for consultation use the website which is the exact representation of github.

  • 1

    perfect ended up not editing much was directly what I found

  • 2

    Complementing: The fourth standard has already been set (PSR-4), which discontinues the PSR-0 for autoloading. And there are three more in draft. PSR-5 for Code Documentation, PSR-6 for cache implementation, and PSR-7 for HTTP request interface.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.