The following coding standards have been used when developing the Mako Framework. We suggest you follow the same standards when developing applications using Mako.
Always use long open tags. Never use short tags or ASP style tags. Class files should never include a closing tag.
// Correct <?php // Incorrect <? // Incorect <%
Files should always have the same name as the class they contain. A file should never contain more than one class. The file encoding should always be UTF-8.
File names should always be lower case in the app directory while files in the libraries folder should have the same case as the class name.
// File: app/controllers/index.php
<?php
namespace app\lib
{
class Index
{
}
}
// File: libraries/mako/DateTime.php
<?php
namespace mako
{
class DateTime
{
}
}
Namespaces should be written in lower case:
// Correct namespace foo\bar; // Incorrect namespace Foo\Bar;
Class names should be written in upper CamelCase:
// Correct class Image // Correct class MyImage // Incorrect class image // Incorrect class my_image
Method names should be written in lower camelCase (does not apply to controller methods):
// Correct public function fooBar() // Incorrect public function FooBar() // Incorrect public function foo_bar()
Variable names should be written in lower camelCase:
// Correct $fooBar = null; // Incorrect $foobar = null; // Incorrect $foo_bar = null;
Constant names should be written in upper case and multiple words should be separated with a underscore:
// Correct
const FOO_BAR = 123;
// Correct
define('FOO_BAR', 123);
// Incorrect
const foobar = 123;
// Incorrect
define('foobar', 123);
Braces associated with a control statement should always be on the next line, indented to the same level as the control statement:
// Correct
public function foo()
{
}
// Incorrect
public function foo() {
}
Tabs should be used for identation while spaces should be used to align code:
<?php
namespace foo;
class Bar
{
public function hello()
{
$string = 'Hello ';
$string .= 'World!';
echo $string;
}
}