Today only I have noticed and found out the importance of using === operator. You can see it in the following example:
$var=0;
if ($var==false) echo "true"; else echo "false"; //prints true
$var=false;
if ($var==false) echo "true"; else echo "false"; //prints true
$var=0;
if ($var===false) echo "true"; else echo "false"; //prints false
$var=false;
if ($var===false) echo "true"; else echo "false"; //prints true
The question is that, are there any situations where it is important to use === operator instead of using == operator?
Of course, just one example:
array_search()Basically if you use any function that returns a value on success but
FALSEon failure, you should check the result with===to be sure (otherwise why would there be a big red warning box? ;))Further examples:
next(),current()or as also mentioned string functions as
strpos(),stripos(), etc.Even
substr()although it is not mentioned explicitly:But what if the extracted part is
"0"? It also evaluates toFALSE, but it is not an error.