Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 8 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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