How far in should your code be indented? What about class names - should they be capitalized? Do we put the opening brace of a function on its own line or not? Somebody just tell me!

With all the possible combinations of coding styles, you can’t expect there to be only one. Certainly, cases can be made for the “one true brace” style as well as any other and they all may have their merits.

There we have at least eight ways of forming a block of code, and that’s not the only issue to consider.

  • Variable naming
  • Class naming
  • Quote types
  • Comment style
  • White space
  • Line length
  • …on and on

In the end it comes down to consistency. Pick something and do it everywhere in that project. Of course, it would make things easier if all of your projects were done in the same style but don’t be afraid to experiment.

And if you’re part of a team, you may not have a say anyway. Everyone on the team should be coding with the same set of guidelines so that the project looks as if it came from one mind.

Perhaps the most widely used standards today are the Zend Framework Coding Standard and PHPDoc (tutorial here). Zend Framework uses the PHPDoc format for inline documentation by the way.

Learning those two will make it easy for you to slip right into just about any project. You’re likely to find that they’ll vary only slightly if at all.