What is a reason of placing boolean or null before comparison operator?

前端 未结 3 1450
刺人心
刺人心 2020-12-11 17:30

In PHP, what is an underlying reason of placing either boolean or null before identical comparison operator?

false === $value;   
null === $value;

3条回答
  •  心在旅途
    2020-12-11 17:48

    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.

提交回复
热议问题