Code Convention for pH7CMS

When working with pH7CMS's code, developing extensions and modifications in the code, this coding convention is highly recommended for your code and have a code easy to proofreading.

Classes And Interfaces: Names

Name Class and Interface: UpperCamelCase (StudlyCaps) and alphanumeric only.
Method Name: camelCasee and alphanumeric only.
Constant Name: ALL_CAPS and alphanumeric only with the underscores to separate words.


class MyClass

    const MY_CONSTANT = 'abcd';

     * @param string $sVal
     * @return string Returns If the $sVal parameter is "abcd", returns "abcd", otherwise "zyxw".
    public function myMethod($sVal)
        if ($sVal == 'abcd')
            return 'abcd';
            return 'zyxw';


In the pH7 Framework

The classes should end with the extension ".class.php" and interfaces must end with ".interface.php".

Variable Declarations: Names

The variables must be in camelCasee and alphanumeric only.

Since PHP is not a typed language, the data found in the variables are fuzzy, so we defined a strict convention for naming variables.
The first letter of the variable must define the type of this: Here is the list of available types:

Data type prefixes:

a = Array
i = Integer
f = Float, Double
b = Boolean
c = 1 Character
s = String
by = Byte
r = Resource
o = Object
m = Mixed

Following the first letter every word used in the Variable Name must begin with a capital letter.


touch('isSunday.txt'); // Creating an empty file
$sFile = realpath('isSunday.txt');

$iDate = date('D');
$bStatus = ($iDate == 'Sun') ? true : false;
$sValue = ($bStatus) ? 'Good Sunday' : 'We are not Sunday';

$rFile = fopen($sFile, 'w');
fwrite($rFile, $sValue);


We use very infrequently (or in a different way) the PEAR coding standards which requires the names of the members (methods and attributes of a class) of a private class to precede it with an underscore (_).
So to distinguish between private and protected members (methods and attributes) of a class.
But you can still follow this convention if you want ;-).
By cons never put members of a class in public (if you do, it means that you do not know enough object-oriented programming to create a module or a code from us).
Also, we rarely respect the "standard" which requires a line must not exceed 80 characters because we believe this standard and obsolete nowadays screens are larger and have a code too long can become very annoying.

Functions, Global Variables and Arrays : Names

Function: lowercase and each word must be separated by underscore.


function my_function() {}

Global variables (Session, Cookie, Registry/Global variables, ...): lowercase and each word must be separated by underscore.



Arrays: lowercase and each word must be separated by underscore.


$aValues = array(
   'my_key' => 'Value',
   'my_key2' => 'Value 2'

or with PHP 5.4 or higher:

$aValues = [
   'my_key' => 'Value',
   'my_key2' => 'Value 2'

PS: We also respect the PSR-0 and PSR-1 coding standards and we try to respect the PSR-2 coding standards but we do not always do that because some things in this new standards
are not easily followed and we do not find this especially well, but you should still try to respect this standard and the PEAR standard for your modules and pieces of code.