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/
Written by Eldad Fux
Related protips
10 Responses
You can't live without them in bigger projects.
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.
@creaktive
how is that related to this tip, exactly?
@creaktive No matter what you think of PHP; it is still a highly used language and tips like these are helpful.
@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.
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.
@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.
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.
@creaktive that's a great link, every PHP developer must read. But is not related to this tip.