PHP: Condition Format - (6 == $var) or ($var == 6)? -
i browsing these php coding guidelines (a bit outdated interesting), , found this:
condition format
always put constant on left hand side of equality/inequality comparison. example:
if ( 6 == $errornum )
...one reason if leave out 1 of = signs, parser find error you. second reason puts value looking right front can find instead of buried @ end of expression. takes little time used format, gets useful.
i have been using ($var == 6)
years , idea of putting them other way around horrifying. mentioned, takes bit time used , supposed have clear benefits. writing standard @ our company if want change this, moment that. i'd hear if other have experience particular format. opinions?
edit
i interested in people's experience making switch. me, , others, looks big change need used to. looks interesting. question have switched: can recommend change?
6 == $var
has real advantage $var == 6
not. there nothing horrifying @ all, looks different. should used , use it. in fact, haven't gotten used yet , forget frequently. have think , use since opposite common.
the advantage, in case didn't know, prevent simple syntactical mistakes, thus:
if ($var = 6) {} //weird semantic error if (6 = $var) {} //parse error
Comments
Post a Comment