Hey, its been a long time since I post anything on this blog but it’s a start.
Today I would like to add programming tips, we all know about condition and comparison especially the “equals to” that sometimes got written as assignment because of one less ‘=’ in the line.
1 2 3 |
if ($var = 'value') { destroy(); } |
Ups, we all got destroyed because of one less character..
To avoid this kind of problem, we could just reverse the position of the compared value with the variable into..
1 2 3 |
if ('value' == $var) { destroy(); } |
So, even if You accidentally missing one ‘=’ character the compiler will generate errors (at least in PHP) and not destroying the humanity.
1 2 3 |
if ('value' = $var) { destroy(); } |
Error : the humanity is saved, err.. I mean “FATAL ERROR syntax error, unexpected ‘=’ on line number x” will be shown if You type this in PHP language.
There You go, no need to thank Me because I also read it somewhere, I just post it here as a reminder for Myself.