“条件分配"背后的基本原理是什么?Zend Studio IDE 中的警告? [英] What's the rationale behind "Assignment in condition" warnings in Zend Studio IDE?

查看:26
本文介绍了“条件分配"背后的基本原理是什么?Zend Studio IDE 中的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:

if ($variable = get_variable('variable')) {
    // ...
}

*$variable = get_variable('variable')* 在 Zend Studio 中引发条件赋值"警告.我明白警告的意思,但有谁知道它背后的原理是什么?仅仅是编码约定、可读性等问题吗?

The *$variable = get_variable('variable')* throws an 'Assignment in condition' warning in Zend Studio. I understand what the warning means, but does anyone know what the rationale behind it is? Is it merely coding conventions, a matter of readability, etc.?

推荐答案

这是 IDE/编译器在大多数允许这种构造的语言中发出的非常常见的警告:因为 = (assignment) 和 ==(比较)非常相似,比较在 if 语句中更为常见,警告只是为了让您知道您可能已经通过您真正想要进行比较的地方出错了.

This is a very common warning issued by IDEs/compilers in most languages that allow this construct: since = (assignment) and == (comparison) are very similar, and comparison is more common within an if statement, the warning is just there to let you know that you may have put in an assignment by mistake where you really intended a comparison.

这篇关于“条件分配"背后的基本原理是什么?Zend Studio IDE 中的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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