Mecha CMS

Updates.

Variable Naming Best Practices

Author: Taufik Nurrohman · 1196 Views

Tweet

Mecha has some disciplines in naming their variables.

Table of Content

General 

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

$site

User variable style should be prefixed with a _ to prevent overwriting 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 defined by the Lot class:

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

$site = Lot::get('site'); // :)
echo $site->title; // :*

Namespace 

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

$my_site

Back-End 

Back-end variables, as you can see them pretty much inside the source code of Panel extension, are prefixed with double _ character:

$__site

Front-End 

Currently not specified. You can use this style if you want:

$site__

Others 

Common variable names using a single letter with their meaning:

  • $aarray container
  • $b → base
  • $cclass, configuration
  • $ddirectory
  • $eevaluate
  • $ffile
  • $g → results of the 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 → ?
  • $s → placeholder, universal variable
  • $t → title, text
  • $uunion, URL, URL part
  • $v → array value
  • $w → ?
  • $x → test, file extension
  • $y → ?
  • $z → ?

6222112321

0 Comments

No comments yet.