将布尔值或null放在比较运算符之前的原因是什么? [英] What is a reason of placing boolean or null before comparison operator?

查看:64
本文介绍了将布尔值或null放在比较运算符之前的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,将布尔值或null放在相同比较运算符之前的根本原因是什么?

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;

代替

$value === false;

这篇关于将布尔值或null放在比较运算符之前的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆