1

Recently, I came across a code like this:

if (0 === $something) { }

Is there any difference between the code above with:

if ($something === 0) { }
  • no, but keep in mind it is different for conditionals like `>==` and `<==` – Patrick Barr Jul 26 '17 at 18:08
  • The Yoda conditions programming style’s intent is to avoid unexpected behavior. It does so by forcing a syntax error when the programmer makes a typo by using an assignment operator (=) when s/he meant to do an equality operator. if (0 == $something) // in case of type 0= $something you are safe – vaquar khan Jul 26 '17 at 18:40

2 Answers2

3

Actually there is no difference in both performance wise or in functional perspective. I can say it's a personal choice of coding style often called that as Yoda Style

In programming jargon, Yoda conditions (also called Yoda notation) is a programming style where the two parts of an expression are reversed in a conditional statement.

I prefer the later way as the first way kills the readability of code (at least for me)

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

No, there is absolutely no difference between the two as the if condition will check for equality between both sides.