Mecha CMS

Updates.

Variable Naming Best Practices

Table of Contents
  1. General 
  2. Namespace 
  3. Others 

Mecha has some disciplines in naming their variables.

General 

Reserved variables in Mecha should match to ^[a-z]+(?:_[a-z\d]+)*$ pattern:

$site

User variable style should be prefixed by a _ to prevent collision with the reserved variables:

$_site

Note: If for a reason, the reserved variables are overwritten, you can always restore the original variable value by accessing the global variables stored in $GLOBALS:

$site = null; // :(
echo $site->title; // :'(

$site = $GLOBALS['site']; // :)
echo $site->title; // :*

Namespace 

Another way to safely writing variables is by namespace-ing your variable name:

$my_site

Others 

Common variable names using a letter with their meaning:

  • $aarray container
  • $b → base
  • $cclass, configuration
  • $ddirectory
  • $eevaluate
  • $ffile
  • $g → results of the g and glob function
  • $h → hint
  • $i → increment, integer, number
  • $j → length of the $a (used in for loop)
  • $k → array key
  • $l → ?
  • $m → matches
  • $nname
  • $o → array container, output container
  • $ppage, path
  • $qquery
  • $r → return value
  • $s → placeholder, universal variable
  • $t → title, text
  • $uURL, URL part
  • $v → array value
  • $w → word
  • $x → test, file extension
  • $y → ?
  • $z → ?