Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been working in a very small team for PHP development and we've been using an ad-hoc, "Invented Here" style guide. Now that our team and codebase is growing, we would like to use a more broadly-used style guide that would be, if not an official standard, a de facto standards used in many PHP communities. Does such a thing exist as it exists in the C/C++/Java/Javascript/etc. circles ?

share|improve this question

closed as off-topic by Ixrec, gnat, zzzzBov, TZHX, MichaelT Feb 17 at 22:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to find or recommend tools, libraries, programming languages, resources (including books, blogs, tutorials, and examples), or projects to undertake are off-topic on Programmers as they attract opinionated answers that won't have lasting value to others. You may be able to get help in The Whiteboard, our chat room." – Ixrec, gnat, zzzzBov, TZHX, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 11 down vote accepted

The PHP Framework Interop Group has released a series of coding standard recommendations:

FIG's recommendations are far from an official standard, and I wouldn't even consider them a de facto standard, but they are the more coherent set of recommendations for PHP we have.

Other than FIG's recommendations, you should take a look at Zend Framework's standards, which include coding style recommendations, and PEAR's standards. Personally I tend to favour FIG's recommendations, they are a bit more coherent than every other set of PHP standards I've seen and are more widely adopted.

You should also take a look at PHP CodeSniffer. It's a tool that detects violations of a defined (and configurable) set of coding standards and can be easily automated via Phing. If you decide to follow FIG's recommendations, you could also use PHP-CS-Fixer to rewrite your code to be PSR-1 and PSR-2 compliant (with a pre-commit hook, for example).

Lastly, keep in mind that the main reason for adopting a coding style standard is consistency, you'll never find a set of standards that will make everyone in your team happy. It doesn't really matter which set of standards you'll pick, what matters is that you pick one and stick with it.

share|improve this answer
1  
Thanks for that very comprehensive answer. – Fabien Mar 25 '13 at 14:22

Yes, there are couple of standards used in the PHP world. Two of them deserve special recomendation.

The PEAR standard, which should be used by all PEAR packages: http://pear.php.net/manual/nl/standards.php

and the PSR standard, which is supported by some big PHP groups like Symfony, PEAR(again), Drupal, Joomla etc. https://github.com/php-fig/fig-standards

share|improve this answer

The official PHP Coding Standard can be found in the root of their project:

https://github.com/php/php-src/blob/master/CODING_STANDARDS

UPDATE: Because people are already starting to down vote my answer. Be sure to actually read the above file. It contains the coding standards for the C part of PHP and for userland code. Specifically lines 136 to 166 are of interest. Of course the rest is also interesting.

TL;DR Build your standard on top of the PHP standard and it looks exactly as the language (from a userland view) does.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.