Code conventions
This are the official programming standards Cherrycake follows.
Last updated
<?php // Use the full PHP opening tag instead of the shorthand <? for compatibility
class ClassName { // Brackets on the same line
var $propertyName = 1 + 3; // Operators surrounded by spaces
// Empty lines between logical blocks are acceptable to add readability
/**
* PHPDoc is used to document code when needed.
* @param boolean $divisor The divisor.
* @return boolean True on success, false on failure.
*/
function methodName($divisor) { // No separation between the method/function name and the parenthesis
global $e; // The Cherrycake engine is stored globally in the $e variable
if ($this->propertyName > 100) // Control structures like if, for, while and switch are one space away from the parenthesis
return false; // Single-line statements without brackets are acceptable, as long as they improve readability
for ($i = 1; $i < 100; $i ++) // Space after semicolons in for control structures
if ($i % $divisor == 0) // Nested control structures without brackets are acceptable, as long as they improve readability
echo "$i is divisible by $divisor"; // Variable interpolation in strings is acceptable when it adds readability
$e->ModuleName->methodName(
$this->propertyName, // Multiline tabbed parameters are acceptable to add readability when the number of parameters is long
[
"id" => $this->propertyName,
"key" => [
"a" => true, // Depth of multidimensional arrays is also expressed with tabs
"b" => 12
]
] // Specially when functions receive complex parameters like this hash array
);
return true;
}
}
// No need to use the ?> PHP closing tag