I know this question is not really important.. however I've been wondering:
Which of the following IF statements is the best and fastest to use?
<?php
$variable = true;
if($variable === true)
{
//Something
}
if($variable)
{
// Something
}
?>
I know === is to match exactly the boolean value. However is there really any improvement?
Using if ($var === true)
or if ($var)
is not a question of style but a question of correctness. Because if ($var)
is the same as if ($var == true)
. And ==
comparison doesn’t check the type. So 1 == true
is true but 1 === true
is false.