[PSR-12] Do not enforce blank line after <?php

313 views
Skip to first unread message

Alexander Makarov

unread,
Jul 31, 2016, 3:19:32 PM7/31/16
to PHP Framework Interoperability Group
The change is part of https://github.com/php-fig/fig-standards/commit/50a3d046baa5143546dc95bf5930d3523f56be6a, made after discussion in a pull request: https://github.com/php-fig/fig-standards/pull/730#discussion_r57308607 and getting some stats on current state of things.

It's about blank like right after <?php:

<?php
declare(strict_types=1);

namespace Vendor\Package;

use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
use Vendor\Package\Namespace\ClassD as D;

use function Vendor\Package\{functionA, functionB, functionC};
use const Vendor\Package\{ConstantA, ConstantB, ConstantC};

class Foo extends Bar implements FooInterface
{

There are three options:

- Enforce blank line. It was like that initially. Style matches Laravel, Symfony and Composer.
- Enforce no blank line. Style matches Yii, Aura, Zend, Slim, Propel, PPI, Doctrine and CakePHP.
- Do not enforce anything. That's what it is after commit.

Since both projects enforcing and not enforcing blank line are major, preliminary decision is not to enforce any particular style i.e. both are valid.

It's definitely preliminary and could be decided otherwise based on the survey to be conducted. Still, it's good to discuss it prior to survey so I'd like your opinions voiced.

Thanks!

Woody Gilk

unread,
Jul 31, 2016, 4:10:09 PM7/31/16
to PHP Framework Interoperability Group
I'd really prefer One Right Way. My personal preference is enforce a
blank line, but PSR-2 does not include that requirement either.
--
Woody Gilk
http://about.me/shadowhand
> --
> You received this message because you are subscribed to the Google Groups
> "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to php-fig+u...@googlegroups.com.
> To post to this group, send email to php...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/php-fig/9178bfbe-56ae-4223-bfed-06b1b08ccd71%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Marc Alexander

unread,
Aug 1, 2016, 2:32:52 AM8/1/16
to PHP Framework Interoperability Group
I don't think enforcing this one way or the other makes sense. There are pros and cons in both directions and in the end this really just comes down to personal taste.
Having one blank line is IMHO more readable while some might argue that the blank line is useless and/or does not improve the readability at all.
To be honest, I don't think this has any impact on the coding style in the end and therefore would recommend to not enforce this.

Woody Gilk

unread,
Aug 1, 2016, 7:12:25 AM8/1/16
to PHP Framework Interoperability Group

The same could be said for every clause in PSR-2, Marc.


--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Larry Garfield

unread,
Aug 1, 2016, 11:39:54 AM8/1/16
to php...@googlegroups.com
Drupal has since tentatively adopted the blank-line style, based in part on the discussion in that thread.

https://www.drupal.org/node/2248463

My own position and that of Drupal's has already been stated in both threads, but to reiterate in short:

* Picking one is important.  A style guide that has a lot of "either/or" in it is weaker, less effective, and harder to both document and implement.  Yes its "personal preference", but so is the entire spec. That's the point. :-)
* The extra space is good, as it makes the entire header section much more consistent. That's easier to remember and easier to document/specify.

--Larry Garfield

scott molinari

unread,
Aug 3, 2016, 12:05:45 AM8/3/16
to PHP Framework Interoperability Group
+1 on blank line - simply looks cleaner IMHO.

Scott

Michael Cullum

unread,
Aug 4, 2016, 5:29:52 AM8/4/16
to FIG, PHP
As with everything in PSR-12, I'm wary of BC-breaks and want to make this a nice upgrade path from PSR-2; that said, this won't hit git commit history of projects too much (it's not modifying lines of code, just adding one) so I'm +1 for picking one.

With regards to what to pick, I think that having a consistent rule in that there should be a blank line between every 'block' in the header makes sense, and is a lot easier to handle than working out which blocks have lines above/below off the top of one's head. Therefore, as it's pretty balanced between projects. However, we can wait for the survey to make any final decisions (for this paying particular attention to the 'would you object' question as opposed to the preference/what do you do now question).

--
Michael C

On 3 August 2016 at 05:05, 'scott molinari' via PHP Framework Interoperability Group <php...@googlegroups.com> wrote:
+1 on blank line - simply looks cleaner IMHO.

Scott

--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+unsubscribe@googlegroups.com.

To post to this group, send email to php...@googlegroups.com.

Alexander Makarov

unread,
Aug 4, 2016, 6:22:50 AM8/4/16
to PHP Framework Interoperability Group
Considering the number of the project which do not have blank line and the fact that it's much higher number than number projects that do have blank line, I think it should be two questions:

1. Should it be enforced at all?
2. Should we enforce blank line or should we enforce no blank line?


On Thursday, August 4, 2016 at 12:29:52 PM UTC+3, Michael Cullum wrote:
As with everything in PSR-12, I'm wary of BC-breaks and want to make this a nice upgrade path from PSR-2; that said, this won't hit git commit history of projects too much (it's not modifying lines of code, just adding one) so I'm +1 for picking one.

With regards to what to pick, I think that having a consistent rule in that there should be a blank line between every 'block' in the header makes sense, and is a lot easier to handle than working out which blocks have lines above/below off the top of one's head. Therefore, as it's pretty balanced between projects. However, we can wait for the survey to make any final decisions (for this paying particular attention to the 'would you object' question as opposed to the preference/what do you do now question).

--
Michael C

On 3 August 2016 at 05:05, 'scott molinari' via PHP Framework Interoperability Group <php...@googlegroups.com> wrote:
+1 on blank line - simply looks cleaner IMHO.

Scott

--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.

To post to this group, send email to php...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages