Next Previous Contents

11. Naming Conventions

11.1 Constants

Constants should always be all-uppercase, with underscores to separate words. Prefix constant names with the uppercased name of the class/package they are used in. For example, the constants used by the DB:: package all begin with DB_.

11.2 Variables

Temporary variables

Temporary variables must have short and brief names. These variables exist only in small blocks of code and there is no need to give them very descriptive names. Particularly numeric variables used in iterations should always be called: $i, $j, $k, $l, $m and $n.

Long living variables

These variables are not necessarily of global scope. They are used in quite long piece of code, so they need to have descriptive but short names to help a reader to understand the code.

Variables should always be all-lowercase, with underscores to separate words. Names should be descriptive but also rather short. Examples below show how to construct variable names in some common cases. Please use given prefixes to make your code easy to read.

Examples:

$max_items
$min_items
$num_items
$sum_items
$arr_items
$prev_item
$curr_item
$next_item

I believe all examples above are self-explanatory.

Global variables

Global variables should always be all-uppercase, with underscores to separate words. Nevertheless you should avoid using globals because they must coexist in global namespace. All globals can be accessed and modified just everywhere in the code. This makes OOP not very OO. Thus, all globals used MUST be accepted by the coreteam.

Example:

$ARR_NAMES = array('name1', 'name2');

11.3 Functions

Function names should meet the long living variables requirements: all-lowercase, underscores to separate words, descriptive and short. Nevertheless you should think twice before creating a function. GNUshop is all-OOP and functions are not OOP-like. All functions MUST be accepted by the coreteam.

Example:

function get_name()
{
    // some code to compute the $name
    // ...
    return $name;
}

11.4 Classes

Class names should always begin with uppercase letter following the "camel caps" style: each word in class name begin with uppercase letter. Simulating hierarchical namespaces use underscores.

Examples:

class DataEngine { }
class User_AccessRights { }

Methods

Methods should be named using the "camel caps" style The initial letter of the name is lowercase, and each word begin with uppercase letter.

Examples:

class BaseClass
{
    public function getName() { }
    public function chkAllNames() { }
}

Properties

Class properties names should always be all-lowercase, with underscores to separate words. Names should be descriptive but also rather short. Follow the long living variables guidelines.

Example:

class BaseClass
{
    private $max_items;
}


Next Previous Contents