This is a question that is bugging me for a long time and can't find any answer... Noticed it's used quite a lot by Zend Framework Developers,
What is the difference between following 2 "if" statements? :
if (null === $this->user) { ... }
if ($this->user === null) { ... }
To me the first one looks kinda odd ;]
Thanks for answer.
It is a good practice for writing
if
statement. Consider this code:If you forgot one equal sign:
Then PHP will generate parse error, so you know you missed one
=
and you can fix it. But this code:will assign 10 to
$var
and always evaluates to true condition. Whatever the contents of$var
, the code above will always echo 'true' and its very difficult to find this bug.