php - What is the reason for ordering an if statement this way? -


why form if statements like...

if (null === $this->foo){...} if (0 === count($bar)){...} 

rather than...

if ($this->foo === null){...} if (count($bar) === 0){...} 

i've noticed in code of number of coders , projects respect don't know why way. second way follows thinking "if value identical null then..." whereas asking "if null identical value..." seems bit less obvious me. so... why?

it's intended ensure don't accidentally put if(this->foo = null) instead of double ==.

this error php catch automatically

if (null = $foo) {} 

while mistake (although can deliberate , useful sometimes)

if ($foo = null) {} 

so, ordering conditions in such way, protect against accidentally assigning value instead of comparing them.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -