nbslvg
Last Updated: February 25, 2016
·
2.323K
· eldadfux
55e7ce99e11493d90f3b61914500ea77

PHP has standards, USE THEM!

Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming etc

PHP FIG

PHP Framework Interoperability Group (Link) is a group composed from representatives from top PHP open source projects to talk about the commonalities between our projects and find ways we can work together. their main audience is each other, but they are aware that the rest of the PHP community is watching and hopefully other folks like you reading this tip will adopt what they are doing in order to create better collaboration in the PHP community.

So far the group has confirmed 4 official standard documents:

  • PSR-0 - Autoloading standard

    Describes the mandatory requirements that must be adhered to for autoloader interoperability.

  • PSR-1 - Basic coding standard

    Comprises what should be considered the standard coding elements that are required to ensure a high level of technical interoperability between shared PHP code.

  • PSR-2 - Coding style guide

    This guide extends and expands on PSR-1, the basic coding standard.

  • PSR-3 - Logger interface

    This document describes a common interface for logging libraries.

Check out more @ http://www.php-fig.org/

10 Responses
Add your response

6632
736212 10200976756252420 836055407 o

You can't live without them in bigger projects.

over 1 year ago ·
6671
321aef6759a26ea37594f3fe1fed9f7a

I know the PHP-FIG is optional, but I'm doing my best to migrate and refactor a lot of old spaghetti code on some projects I've been taken on to work on. Some of it's not possible when working on older versions of PHP, which I have to, but as long as you keep the principles of the FIG in mind, it really helps.

over 1 year ago ·
6717

@creaktive
how is that related to this tip, exactly?

over 1 year ago ·
6734
1e2f853daf9982191625f20f6eb667da

@creaktive No matter what you think of PHP; it is still a highly used language and tips like these are helpful.

over 1 year ago ·
6759
40cd1350403e5f6511745afed34d69ae

@creaktive No language is perfect or will be perfect, because there is no perfect programmer. Love them, hate them, but do it quietly and more important without trolling.

over 1 year ago ·
7178

I find it is best to define Coding Standards at a company/organisation level. Ever where I have worked has either had Coding Standards or I have introduced them.

The PHP Standers in our company are similar to FIG, but there are a number of differences. Notably "Opening braces for classes MUST go on the next line" we do not agree with. We have the rule "Opening braces for classes MUST go on the same line the same as conditional statements".

If FIG would just change that, the rest of it seams to be OK.

over 1 year ago ·
7180
55e7ce99e11493d90f3b61914500ea77

@hpoom I feel the same way about the FIG rule saying opening braces for classes must go on the next line but I also believe the most important thing about coding standards is that consistency is much more important than any personal preference.

over 1 year ago ·
7181
2bebf4cb2fc99965264410111a0d2239

I agree with @hpoom. Doing it at the company level is a much better approach, as not every rule should be followed. I have a hard time agreeing with a lot of the FIG style guide rules as it is.

over 1 year ago ·
7182
Tiagox.in

@creaktive that's a great link, every PHP developer must read. But is not related to this tip.

over 1 year ago ·