Use tabs, not spaces.
$message = 'Hello, world'; $messages = array(); $coolStuffHere = 7; $Message = new Message(); $wgGlobalMessages = array();
/* Functions start lowercased */
function reallyGreatFunction()
{
}
/* Functions in the global namespace are prefixed with 'wf' */
function wfReallyGreatFunction()
{
}
/* Objects start uppercased */
class FooBar
{
private $variable;
public function FooBar()
{
}
/* Small functions can be one lined */
public function getVar() { return $this->variable; }
protected function doSomething()
{
}
}
TODO: How to document the author? @note, @author??? Ideas?
/**
* User Creation
* @param string $firstName the user's first name
* @param string $lastName the user's last name
* @return int $userId user's new id
*
* @note Creates a new user
*/
private function userCreate($firstName, $lastName)
{
}
// CORRECT
if ($foo > $bar)
{
}
// INCORRECT
if ($foo == $bar)
//code here for the true case
if ($foo == $bar)
//code here for the true case
// CORRECT: Add spaces to make the conditional easier to read
if ( ($a > $b) || ($c == $d) && ($e <= $f) ^ ( ( (!$g) && ($h < $i) ) || ($j) ) )
{
}
else if ( ($a== $b) && ($c == $d) )
{
}
// INCORRECT
if (($a>$b)||($c==$d)&&($e<=$f)^(((!$g)&&($h<$i))||($j)))
{
}
else if (($a==$b)&&($c==$d)
{
}
Usage of parentheses within the operation is up to the coder's discretion.
echo $foo == $bar ? 'OK' : 'Nope'; echo $cond ? 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt' : 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum.'; $var = $foo > $bar ? $baz : 28; $seven = (1 < 3) ? 7 : 6; return ($a ^ $b) ? 1 : -1;
echo('Foo' . 'Bar');
echo('Foo'. $baz .'Bar');
echo('Foo' . $baz . 'Bar');
// Special character usage
echo("\t" . 'Foo Bar' . "\n");
// Multiline strings
echo('<a href="'. $url .'">'. 'Page ' . $pageName .'</a>'.
' More long text here...' . "\n");
// Alternate method, printf
printf('<a href="%s">Page %s</a>' . "\n", $url, $pageName);
// DO NOT do this
echo 'Foo'.$baz.'Bar';
echo "Foo".$baz."Bar";
echo "Foo{$baz}Bar";
echo '<a href="'.$url.'">'.'Page '.$pageName.'</a> More long text here...'."\n";
//CORRECT
$string = 'Hello, world';
<?php echo($string); ?>
<?php echo('Hello, world'); ?>
//INCORRECT
<? echo($string); ?>
<?=$string?>