Why PSR?

Hello, today I want to say few words about PSR and answer to questions:

  1. What is this PSR?
  2. Why must everybody use PSR?
  3. Which PSR number is important to me?
  4. It is true that everybody must use it?

1. What is this PSR?

The PHP Standard Recommendation (PSR) is a PHP specification published by the PHP Framework Interop Group. Which describes rules of programming to provide a common technical basis for an implementation of proven concepts for optimal coding. It is about how we should write code in a way that it’ll be easily readable and usable by others. Not only to other peoples but also other applications, generators, and others not humans.

2. Why must everybody use IT?

Short answer: It’s not true.

Long answer: If you ask such a question, probably you don’t need to use it. Some of PSR rules are so obvious that everybody knows it and nobody argues. If you use composer and you still wonder is PSR good for your project… You must think twice.  PSR is good, standards are good but unfortunately you must consider which is good for you.

3. Which PSR number is important to me?

This is a tricky question.

According to the PSR Workflow Bylaw, each PSR has a status as it is being worked on. Once a proposal has passed the Entrance Vote it will be listed here as “Draft”. Unless a PSR is marked as “Accepted” it is subject to change. The draft can change drastically, but Review will only have minor changes.

As also described in the PSR Workflow Bylaw. The Editor, or editors, of a proposal, are the essentially the lead contributors and writers of the PSRs and they are supported by two voting members. Those voting members are the Coordinator who is responsible for managing the review stage and votes and a second sponsor.

In simple words – PSR with status accepted, but it depends on what are you typing.

4. It is true that everybody must use it?

No.

If you write your code just for your own – no.

If your code is old and is working on the old platform in the specific environment – no.

Also, your code can break all  PSR rules and it still can be a great application which is doing its jobs.

So my conclusion – rules are good, but we can also break them

You must admit – this is beautiful

<?php
namespace Vendor\Package;

abstract class ClassName
{
    protected static $foo;

    abstract protected function zim();

    final public static function bar()
    {
        // method body
    }
}

Hope this helps you in struggling with PSR – PSR is gooood.