php

Understanding PSR — Part 1 What Does PSR means?

I keep seeing young developers these days completely depended on Frameworks, while it provides a way to finish our work faster but you won’t learn until get inside their core. when it comes to basic of understanding, it starts with how files are loaded and how various internal libraries are linked to each and easily retrieved with just using a Namespace Keyword. There it comes in Understanding PHP PSR first.

Understanding PHP PSR Means?

PSR or PHP Standards Recommendations (or sometimes called Proposed Standards Recommendation), is an attempt to standardise the way people use PHP. As the growth of frameworks has been increasing dramatically, there comes the need for “Interoperability” between these framework. So one can you other packages/plugins/modules are whatever without any trouble.

Just think about it, if each frameworks are written in different styles (like coding styles, use of including file set, linting, logging, etc) it be a hell for other developers to understand and how to use it. There comes the need for developers (Since PHP is Open Source) to come point to finding a neat way, i.e rules or proposed “standard” of how to write PHP.

I remember my time when started out programming in PHP like 7 years back, there always comes a need to use third party vendor packages, what i did was download from the web, extract and put it somewhere and use ‘require’ to load. I had no idea about standards or proper convention of how to use a component and also I put up ‘require’ in all my classes and create instance in same manner, now i look into it, it’s so stupid. Its like 5 or 10 vendor components are download and extract and placed in everywhere. When sharing with collaborators, I just blindly commit these extracted packages in my repo. Even if i dynamically include these packages, each plugin requires different ways to load in runtimes. Its like Hell, until i found it there is something called PSR and Composer.

How it Started?

  • Started as “PHP Standards Group” after a initial conference in 2009 (according to http://code.tutsplus.com/tutorials/psr-huh–net-29314)
  • Later changed to “Framework Interoperability Group” or simply FIG, as former wasn’t clear about the intention of creating such a group.

How FIG Work?

  • The whole thing is based on Voting by PSR Workflow ByLaw (http://www.php-fig.org/bylaws/psr-workflow/)
  • Proposal are made in FIG and voted for acceptance
  • Status change over from Accepted, Review, Draft and deprecated
    • Unless a PSR is marked as “Accepted” it is subject to change.
    • Also we should not use Draft which can change drastically,
    • Review will only have minor changes.
  • The above FIG has group people voters from varity of projects/frameworks Like Symfony, CakePHP and also from phpDocumentor, Composer (ofcourse!) http://www.php-fig.org/members/
  • Now hopefully we’ve understand what does PSR means. Now, lets see what are PSR accepted/approved standards. Each PSR are represented by PSR-N, where N is PSR version number.

PSR Approved/Accepted Standards:

  1. Basic Coding Standard – PSR-1
  2. Coding Style Guide – PSR-2
  3. Logger Interface – PSR-3
  4. Autoloading Standard – PSR-4
  5. Caching Interface – PSR-6
  6. HTTP Message Interface – PSR-7

In our next blog we’ll see about how to use “PSR-4” Autoloading standard and “PSR-1, PSR-2” Coding standards.

Leave a Reply