gpt4 book ai didi

zend-framework - Zend Studio 报告警告 : Assignment in condition. 这很糟糕吗?

转载 作者:行者123 更新时间:2023-12-03 16:19:29 27 4
gpt4 key购买 nike

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

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

要停止警告,代码需要这样编写:
$q = query("select * from some_table where some_condition");
$f = fetch($q);
while ($f) {
// some inner workings
$f = fetch($q);
}

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

我知道警告可能旨在阻止这样的错误:
$a = 1;
while ($a = 1) {
// some inner workings
$a++;
}

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

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

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

出锅,入火。

最佳答案

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

关于zend-framework - Zend Studio 报告警告 : Assignment in condition. 这很糟糕吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/630035/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com