In PHP, what is an underlying reason of placing either boolean or null before identical comparison operator?
false === $value;
null === $value;
It seems to me that it is same as saying
$value === false;
Is it just a personal preference or there is a concrete reason why people do this?
It's a convention to avoid the mistake of accidentally assigning a variable.
$value = false;
instead of
$value === false;
This is sometimes referred to as Yoda-conditions, there's a fun list of all such constructs and their unofficial names.
No there's no real difference between $var === false
or false === $var
, some people claim it's easier to see what is being checked for if the bool is the left operand, other hate it... In short: personal preference is what it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With