Problem/Motivation
PSR-2 and PSR-1 are accepted coding standards: https://github.com/php-fig/fig-standards/tree/master/accepted.
There is a list of peoples that voted (https://github.com/php-fig/fig-standards/blob/master/README.md):
- Nate Abele: Lithium
- Nils Adermann: phpBB
- Brett Bieber: PEAR, PEAR2
- Guilherme Blanco: Doctrine, Doctrine2, et al.
- Jordi Boggiano: Composer, Packagist
- Karma Dordrak: Zikula
- Paul Dragoonis: PPI, PPI2
- William Durand: Propel, Propel 2
- Andrew Eddie: Joomla
- Cal Evans: the community at large
- Larry Garfield: Drupal
- Paul M. Jones: Solar Framework, Aura Project
- Robert Lemke: FLOW3
- Larry Masters: CakePHP, CakePHP 2
- Evert Pot: SabreDAV
- Ryan Parman: Amazon Web Services SDK
- Fabien Potencier: Symfony, Symfony2
- Andre Romcke: eZ Publish
- Paul Scott: Chisimba, C4
- Phil Sturgeon: PyroCMS
- Kris Wallsmith: Assetic, Buzz
- Matthew Weier O'Phinney: Zend Framework, Zend Framework 2
- David Zülke: Agavi
The results of the vote were posted in the PHP-FIG group.
It seems like Drupal leads are in the list too. So the PSR-2 (and PSR-1 too) has some cons and pros, but for better interoperability between libraries I suggest to consider of using them for Drupal 8.
For example, I use (and I think many other peoples) other libraries. It is inconvenient for me change my code style, IDE settings and so on between Drupal and other libraries that supports PSR-2 like Symfony (http://symfony.com/doc/current/contributing/code/standards.html), ZF 2 etc. Personally I prefer some mix of Drupal and PSR-2 coding standards, but I need to follow common and modern trends in the PHP world.
What you think about that?
Resolution
According to #4, Drupal will not be adopting the PSR-2 and PSR-1
#9 gives more details,
Drupal originally implemented PSR-0 but has moved to support PSR-4 instead. see: https://www.drupal.org/node/1971198
Drupal does not support PSR-1 or PSR-2, Drupal has it's own rigid code standards.
Drupal supports the PSR-3. see: https://www.drupal.org/node/1289536
Comments
Comment #1
hinikato CreditAttribution: hinikato commentedAs one more suggestion: keep current standard for files with functions but use PSR-2 for files with classes.
Comment #2
dcmouyard CreditAttribution: dcmouyard commentedFYI - I read somewhere (maybe IRC) that Drupal 8 will not be adopting PSR-1 or PSR-2. The current Drupal coding standards will not change.
Comment #3
sunRight, Drupal will not adopt PSR-1 and PSR-2.
Further reading here:
http://www.technosophos.com/content/when-standard-bad-standards-body
http://engineeredweb.com/blog/practical-problems-psr-2/
Comment #4
gagarine CreditAttribution: gagarine commentedArrrgh! Than mean I will have to change my IDE settings and habits when I switch from symphony to Drupal... As those two projects become closer it will make sens to use the same coding standards.
We can also benefit from tools developed for symphony/PSR-x like http://cs.sensiolabs.org/ . BTW with a tools like that it should be easy to change automatically the code style in all DO projects...
Comment #5
sunGet a better IDE.
Comment #6
gagarine CreditAttribution: gagarine commented@sun I'm sorry to say your answer is offensive and make you look arrogant. You made a tons of good works and I totally respect you, I wait the same for you. More than that it was discussed on IRC and their was perhaps good arguments against using PSR-2... but the two links you add didn't convince me. So I guess others peoples are going to re-open this bug.
Comment #7
AlessMascherpa CreditAttribution: AlessMascherpa commentedPSR-2, even it has good points, is not cool. Arguments are cleanly stated by Matt Farina in http://engineeredweb.com/blog/practical-problems-psr-2/ In short: "The web is wider than PHP". Also Coding style standards are very important for development, but offer little to real interoperability between projects.
For those curious about Drupal leads vote -> Larry Garfield's vote on that topic in the PHP standards discussion group: https://groups.google.com/d/msg/php-fig/c-QVvnZdMQ0/EHbiF_sCkDwJ
I'm glad that Drupal stays with his coding style standard, even I prefer camelCaseNames rather than underscore_names :)
Cheers
Alessandro.
Comment #8
ro-no-lo CreditAttribution: ro-no-lo commentedMy guess is Drupal until D10 or so will only adopt PSR-0 and maybe PSR-3.
A lot of core developers are still on their framework island. I personally, als long term drupaller, would prefer to switch between kohana, zend, drupal, symfony and feel visually in every source code at home, because of PSR-1 and PSR-2 acceptance.
Drupal 8 will be a mix of at least two or more coding standards, because of the libraries used. If you have to fix something in a library which may be taken from Yii you will roll eyes. Because their codeing standard is the worst I have ever seen. From the Yii project lead here: http://www.yiiframework.com/forum/index.php/topic/3667-coding-standard/
Time will tell. I vote for PSR-1 and PSR-2 for Drupal. (Even though I prefer the 2 spaces indents)
Comment #9
cosmicdreams CreditAttribution: cosmicdreams commentedI found this page because I searched for PSR-2 today.
To those who stumble across this post and read through the comments. Here's a snapshot of Drupal's support for PSRs:
Drupal originally implemented PSR-0 but has moved to support PSR-4 instead. see: https://www.drupal.org/node/1971198
Drupal does not support PSR-1 or PSR-2, Drupal has it's own rigid code standards that can quickly and easily be used in modern IDEs such as PhpStorm.
Drupal supports the PSR-3. see: https://www.drupal.org/node/1289536
Comment #10
bojanz CreditAttribution: bojanz commentedAs far as I can see, there's no incompatibility between Drupal's coding standards and PSR-1.
Only PSR-2 is the "problematic, won't fix" one.
Comment #11
timmillwoodHonestly shocked to see D8 won't be officially PSR-1 or PSR-2, especially with the PHP-FIG endorsement of these standards from Crell (the Drupal representative).
It looks like we're already PSR-1 compliant but I think, like the components we're using, we should adopt PSR-2.
I am reopening, albeit as "Postponed" and moving to D9. It'd be awesome to get this into a point release of D8, but would need to evaluate the implications of updating coding standards in a point release. This has been done in other projects, for example Laravel 5.0 used PSR-1 + custom standards but Laravel 5.1 is now using PSR-2.
Comment #12
Crell CreditAttribution: Crell at Palantir.net commentedtimmillwood: The Drupal FIG representative voted against PSR-2, not for it.
Our OOP code is, I believe, all PSR-1-friendly already but we should confirm that.
Comment #13
timmillwood@crell - Sorry for the missunderstanding
When I get time I will run
php-cs-fixer fix --level=psr1
against the codebase to check we're at least PSR-1.Comment #14
catchLooks like this is the right status.
Comment #16
quietone CreditAttribution: quietone at PreviousNext commented