Zend Studio reports warning: Assignment in condition. Is this so bad?

后端 未结 8 1649
轻奢々
轻奢々 2020-12-11 02:47

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_conditio         


        
8条回答
  •  情书的邮戳
    2020-12-11 03:18

    The reason it's bad is alot of people use "=" when then meant "=="

    The = operator will return the assigment to the left so if you use if($x=true) the code within the if will be run, if you use if($x=false) the code will not be run. It's a neat trick that can save a line or two of code but it's also dangerous because if you meant if($x == false) and typed if($x = false) it will be a bug that can be difficult to track down.

提交回复
热议问题