Skip to content

Code Style Guide: PHP

ginatrapani edited this page Sep 13, 2010 · 20 revisions

This is the Code Style guide for PHP. See the main Code Style Guide page for other languages.

Assume we’re using the Drupal PHP coding style unless otherwise noted here.

Always use <?php to delimit PHP code, not the shorthand, <?, as this is the most used and supported across PHP setups and the one PHP will continue supporting in the future.

Use PHP5 style code conventions

  • Class constructors should be public function __construct(). Use destructors when appropriate.
  • Explicitly declare visibility (public, private, protected) for member variables and methods.
  • As per Zend framework style guide, do NOT use PHP closing tags:
    “For files that contain only PHP code, the closing tag (”?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response."

Include Docblocks on All New Code

Thinktank uses PHPDocumentor to ease code maintenance and auto-generate class documentation. Include “docblocks” in all of your code. When writing your documentation, please use PHPDocumentor’s syntax.

MVC Architecture

ThinkTank implements the Model-View-Controller design pattern. All new PHP code should follow suit. Read more about ThinkTank’s MVC implementation.

Clone this wiki locally