Are there standard style guides for PHP? [closed]

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 ?

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

  • PSR-0: Autoloading Standard
  • PSR-1: Basic Coding Standard
  • PSR-2: Coding Style Guide (this is what you are looking for)
  • PSR-3: Logger Interface

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.

0

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

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.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật