Skip to content

POSSA PHP Style Guide

rdegges edited this page Nov 19, 2012 · 4 revisions

In order to make writing, reading, and maintaining all our POSSA projects as simple as possible, this style guide sets some basic guidelines all developers should follow when working on POSSA PHP codebases.

While we haven't enforced strict style rules in the past, all future pull requests will be reviewed for proper style to ensure a high quality, frustration free codebase :)

The Rules

Above all, there are several style rules you should always keep in mind:

  • Use soft tabs instead of spaces when indenting. This means that your editor should be configured to insert a \t character for each indentation, as opposed to multiple space characters. This helps keep the PHP code uniform, and helps the POSSA PHP code blend in with other popular PHP projects.

  • When displaying tabs in your editor, they should be displayed as 4 spaces. This means that each tab character you have (\t) should be represented as 4 characters in length. This way, when you're writing code, you'll always have the same margins regardless of what project you're working on.

  • Use same-line curly braces, for instance:

    // WRONG
    if ($x == 'hi')
    {
        $x = 'yo!';
    }
    
    // RIGHT
    if ($x == 'hi') {
        $x = 'yo!';
    }