PHP: PSR-2: Why blank lines after namespace / use declarations?

3.3k views Asked by At

So I was going over the PSR coding standards the other day (which I duly follow), and Ive kind of always understood the reasons for everything, and mostly coded that way for everything Ive worked on over the last 10+ years as very similar standards were heavily forced upon me in my university days - it just stuck.

However, I do wonder about this note in the PSR-2 standards:

There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations.

Why is this? I dont object to it, but Im sure there is some kind of background or history to explain, and it never really jumped out to me as why. I guess the obvious reason is legibility, but I have a feeling like there are deeper reasons for this standard.

While I'm at it - does anyone know of any good resources to explain the logic behind all of the PSR guidelines? Its useful to have an official reasoning and history which led to specific standards when trying to convince others to follow them, whom may not be convinced its in their best interests.

2

There are 2 answers

0
bishop On BEST ANSWER

I think the best resource you're going to get is the PHP-FIG mailing list, specifically the archive on Google Groups. Here are some interesting discussions related to your question:

My personal recollection is that the standard came about as a blending of PEAR2, PHPCS, Doctrine1 and Flow3 styles. But all this was 5 years ago, and I have forgotten all about it.

2
Ja͢ck On

Well, what looks better? This:

namespace Foo;
use Bar\Baz;
use Bar\Qux;
function test()
{
}

Or this:

namespace Foo;

use Bar\Baz;
use Bar\Qux;

function test()
{
}

I think it speaks for itself.