41

I've recently been shaking up my coding habits and have been toying with various approaches to coding style... things like using a space between method call parentheses and the parameters they contain, how to deal with multi-line array definitions and method calls, etc.

I'm wary of creating my personal flavor of everything, though, and want to skim through some well-regarded "authoritative" style guides. Which ones should I look at? I've had a hard time finding much other than the Zend guide.

keithjgrant
  • 12,421
  • 6
  • 54
  • 88

3 Answers3

55

The PHP Standards Recommendations by the PHP Framework Interoperability Group are a good resource. AFAIK the standards are highly regarded. They attempt to be a collection and unification of what different frameworks have decided to use as their own standards.

I would say for basic PHP coding, especially PSR-1 and PSR-12 are well worth a read.

PSR-2′s purpose [was] to have a single style guide for PHP code that results in uniformly formatted shared code. [The PSR-12] specification extends, expands and replaces PSR-2, the coding style guide and requires adherence to PSR-1, the basic coding standard.

There are several accepted standard recommendations.

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50
Ilari Kajaste
  • 3,207
  • 2
  • 23
  • 25
  • **PSR-12** has been replaced by the [PER Coding Style](https://www.php-fig.org/per/coding-style/) – MatJB Jul 13 '23 at 14:45
8

I just use the PEAR coding standards.

http://pear.php.net/manual/en/standards.php

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
5

This is really for Codeigniter, but it's still PHP and an easy read and I like the styles used:

https://www.codeigniter.com/userguide2/general/styleguide.html

sitesbyjoe
  • 1,861
  • 15
  • 21