Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is switching an if-statement around bad practice? [closed]

Tags:

if-statement

I can remember being told that having an if statement like if(10 == $myVariable) is a bad practice. However, why is this a bad practice and what is its name? (I can vaguely remember that it has a specific name).

like image 381
Ruben Rutten Avatar asked Dec 03 '22 18:12

Ruben Rutten


1 Answers

its good practice because of accidental typos

if (10 = $myVariable)  

will not compile where as

if ($myVariable = 10)

will and make the if statement true, and also set $myVariable to 10

is a fairly easy to make, and hard to spot error.

http://en.wikipedia.org/wiki/Yoda_conditions

like image 135
exussum Avatar answered Feb 24 '23 00:02

exussum