Variable Naming Best Practices
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:
$a
→ array container$b
→ base$c
→class, configuration$d
→ directory$e
→ evaluate$f
→ file$g
→ results of theg
andglob
function$h
→ hint$i
→ increment, integer, number$j
→ length of the$a
(used infor
loop)$k
→ array key$l
→ ?$m
→ matches$n
→ name$o
→ array container, output container$p
→ page, path$q
→ query$r
→ return value$s
→ placeholder, universal variable$t
→ title, text$u
→ URL, URL part$v
→ array value$w
→ word$x
→ test, file extension$y
→ ?$z
→ ?
0 Comments
No comments yet.