why are assignments in conditions bad?

后端 未结 6 475
长发绾君心
长发绾君心 2020-12-16 09:45

I am using NetBeans for PHP 6.5.

In my code I frequently use the following type of command:

if (($row = $db->get_row($sql))) {
        return $row         


        
6条回答
  •  星月不相逢
    2020-12-16 10:32

    In languages that allways return a value on assignments it's not bad (I think it's quite common in functional languages), but (as others allready have said while I typed this) it should usually be avoided since you or someone else might mistake it for a comparison. The compiler should usually warn about it, but it can be ignored if you're sure what you're doing...

提交回复
热议问题