Report a problem

Coding standards


These standards for code formatting and documentation must be followed by anyone contributing to Monstra. Any contributions that do not meet these guidelines will not be accepted.


File Formatting


PHP tags


Always use long open tags. Never use short tags or ASP style tags.Files containing only PHP code should always omit the closing PHP tag (?>). This prevents many of the elusive white screens of death.


Indentation


All indentation should be done using real tabs, NOT spaces. But aligning things after the indentation should be done using spaces, NOT tabs.


Line Endings


Line endings should be Unix-style LF.


File Naming


All file names must be all lower case. No exceptions.


Encoding


Files should be saved with UTF-8 encoding and the BOM should not be used.


Naming Conventions


Classes


Class names should use CamelCase style, and each word in the class name should begin with a capital letter.


class Blog {
}

Function/Methods


Function/Methods names should use lowerCamelCase style, and each word in the Function/Methods name should begin with a capital letter.


class Blog {
    function getPost() {
        // Some code here...
    }
}

Variables


Variable names should be concise and contain only lower case letters and underscores. Loop iterators should be short, preferably a single character.


$user_login = 'Awilum';

Constants


Constants follow the same guide lines as variables with the exception that constants should be all upper case.


THEMES
PLUGINS
PLUGINS_BOX

Keywords


Keywords such as true, false, null, as, etc should be all lower case, as upper case is reserved for constants. Same goes for primitive types like array, integer, string.


Control Structures


The structure keywords such as if, for, foreach, while, switch should be followed by a space as should parameter/argument lists and values. Braces should be placed on a same line.


for ($j = 1; $j < 5; $j++) {
    for ($j = 1; $j < 5; $j++) { 
        doSomething(); 
    }
} 
if ((condition1) || (condition2)) {
    // Action 1
} elseif ((condition3) && (condition4)) {
    // Action 2
} else {
    // Default action
} 
// Space before and after '!'
if ( ! condition) {
    // Do something...
}