Zend Studio 报告警告:条件分配.这有那么糟糕吗? [英] Zend Studio reports warning: Assignment in condition. Is this so bad?

查看:20
本文介绍了Zend Studio 报告警告:条件分配.这有那么糟糕吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用 Zend Studio,它报告了以下类型的代码警告:

I have recently started using Zend Studio which has reported as warning the following type of code:

$q = query("select * from some_table where some_condition");
while ($f = fetch($q)) {
  // some inner workings
}

要停止警告,代码需要这样编写:

To stop the warning the code needs to be written like this:

$q = query("select * from some_table where some_condition");
$f = fetch($q);
while ($f) {
  // some inner workings
  $f = fetch($q);
}

为什么这被标记为警告?有这么惨吗?

Why is this marked as a warning? Is it so bad?

我了解警告可能旨在阻止这样的错误:

I understand that the warning may be designed to stop errors like this:

$a = 1;
while ($a = 1) {
  // some inner workings
  $a++;
}

它永远不会终止,因为 1 被分配给 $a,而 $a 又返回 1 给 while 语句,而不是针对 $a 进行测试并在 $a 不是 1 时返回 false 给 while 语句.

which will never terminate because 1 is being assigned to $a which in turn returns 1 to the while statement, rather than being tested against $a and returning false to the while statement when $a is not 1.

容易犯的错误,它可能会验证警告,授予,但忘记在第二个示例中的 while 块末尾添加额外的 $f = fetch($q) 这也将导致循环永远不会终止.如果我更改代码以删除警告,然后忘记在 while 块的末尾添加 $f = fetch($q),Zend 将不会对此发出警告!

Easy error to make which may validate a warning, granted, but so is forgetting to add the extra $f = fetch($q) at the end of the while block in the second example which will also result in a loop that will never terminate. If I change my code to remove the warning and then forget to add the $f = fetch($q) at the end of the while block Zend won't warning be about that!

因此,通过删除有关常见错误的警告,我正在为不同的常见错误做好准备.

So by removing the warning concerning a common error I'm setting myself up for a different common error.

出锅,入火.

推荐答案

while (($row = $sql->db_Fetch("MYSQL_ASSOC")) != false)

这篇关于Zend Studio 报告警告:条件分配.这有那么糟糕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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