Skip to content

Instantly share code, notes, and snippets.

@binarypie
Created September 2, 2009 16:45
Show Gist options
  • Save binarypie/179820 to your computer and use it in GitHub Desktop.
Save binarypie/179820 to your computer and use it in GitHub Desktop.
PHP Code Style Guideline
<?php
/**
* Please use doxygen notatin when creating documentation for classes and functions
* Code indentation is 4 spaces DO NOT USE TABS!!
*
* @param object $object This object does something
* @param int $options This integer can count by one
* @return echos json This function returns something
*/
// Namespaces must match folder structure
namespace Application\Controllers;
// Antiframework is included by default when the application loads and should be aliased in every class that needs access to it
use \AntiFramework as AF;
// Required classes should be aliased by the class name
use \Application\Exceptions as Exceptions;
use \Application\Managers as Managers;
use \Application\Helpers as Helpers;
// Class names are camel case
class ClassName extends BaseController {
// All variables names are camel case
private $variableName = 'All Variable Names Are Camel Case.';
// Function names are lower case with underscores
public static function do_some_thing() {
// All comments are singe line // style and should begin with a space followed by a capital letter
// TODO: Should being with a capital letter
// START HACK: TITLE SHOULD BE IN UPPER CASE
// Followed by a description of the reason behind the hack following normal comment style
$this->variableName = 'Something really strange';
// END HACK
// Array keys are lower case with underscores
$someArray = array(
'foo_bar' => $this->variableName
);
// Array acessors use single quotes
$someArray['foo_bar'];
// Strings use single quotes
$someString = 'Strings use single quotes';
// Strings concatenation
// Do not put spaces between the values
$someString = 'Hello '.$text.' World'; // Correct
$someString = 'Hello ' . $text .' World'; // Incorrect
$someString = "Hello $text World"; // Incorrect
// Simple If
if ($oneThing > $anotherThing) {
// Do things
}
// Complex If
if (
($twoThings > $threeThings) &&
($oneThing < $fiveThings)
) {
// Do more things
}
// Switch style
switch ($foobar) {
case 'One':
// One
break;
case 'two':
// Two
break;
default:
// The end
}
// For style
for ($x=0;$x<10;$x++) {
$y += $x;
}
// For each style
foreach ($collection as $item) {
echo $item->name.' is really nifty!';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment