Practical Problems With PSR-2

PSR-2 is a recent standard released by the Framework Interoperability Group (FIG) that a number of people have called into question. I’m definitely one of them. FIG is a self appointed group of PHP developers trying to create standards to help interoperability between the different PHP projects they work on. Unfortunately, they failed to take a number of practical things into account.

Some Background

To date, FIG has released 3 standards in PSR-0 that deals with class autoloading. I’ve not heard many people complain about this and it’s been around for years. PSR-1 was created at the same time as PSR-2 and outlined just a few coding standards that aren’t controversial. PSR-2 is the one that’s causing the commotion. It is a fairly opinionated coding standard.

Practical Problems

The basis for my problems definitely comes from my point of view. When I write PHP I’m writing for the web. For example, I’m not going to try to write a desktop application in PHP. When I write for the web it’s in a mix of languages. I regularly use JavaScript, sometimes I use Ruby, and have even been using some Python.

Interoperability on a web project means interoperability between JavaScript and PHP. Interoperability in my regular workflow mean numerous different language.

This is where PSR-2 fails for me in practical usage. When PSR-2 was created they looked at a number of PHP projects and surveyed what they were doing. But, it appears they didn’t look at the standards for the other languages and projects we’re using. For example, checkout the github style guide, Felix’s Node Style Guide, and the community driven Ruby style guide.

These style guides all have a lot of similar features. For example, a 2 spaced indentation rather than 4 spaces or tabs. For a function definition the opening { is on the same line as the function definition. They all appear to flow well together.

Then you bring the PHP one into the workflow and it’s different. It doesn’t fit in. From a practical standpoint in my daily workflow it’s awkward to use.

Ultimately, I would like to see a PHP style guide that flows nicely with that of other languages I work with. Especially when multiple languages are in the same project. Building applications for the web is often about a mix of languages. Having styles that nicely flow together helps out in everyday coding.

Note: My cohort Matt Butcher just released a posted about PSR-2 title “When is a Standard Bad for a Standards Body?”. If you are interested in this topic consider reading that post.