检查变量的值时,反向条目(null === $ value)的含义是什么? [英] What's the meaning of the reverse entry (null === $value) when checking the value of the variable?

查看:286
本文介绍了检查变量的值时,反向条目(null === $ value)的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP - 在if语句中颠倒顺序

检查空 - 什么订单?

检查Zend Framework发现他们以相反的方式执行所有变量检查:

Examining Zend Framework found that they do all the variable checkings reverse way:

public function setBootstrap($path, $class = null) {

   if (null === $class) {    // instead of if($class === null)
      $class = 'Bootstrap';
   }

这样做的原因是什么?

这是否也适合Java和C ++编程?

Is this also suitable for Java and C++ programming?

推荐答案

有些人认为它有助于他们避免写一个 = (一个赋值而不是相等的比较)

some people believe it helps them in avoiding to write a single = (an assignment instead of a comparison for equality)

我相信这样做的好处远远低于可读性的损失(因此可维护性!)

I believe that the advantage of doing so is much less than the loss of readability (and therefore maintainability!)

不测试代码的人可能会依赖这种技巧。并且回答你的问题,是的,它适用于从C语言派生语法的大多数语言 - 我的意思是合适的,不推荐。

People who don't test their code may rely on this sort of trick. And to answer your question, yes, it is suitable for most languages who derive their syntax from C - I mean suitable, not recommended.

这篇关于检查变量的值时,反向条目(null === $ value)的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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