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

后端 未结 8 1630
轻奢々
轻奢々 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:39

    So you won't have to rewrite all your code without a decent reason: You can disable the detection of this potential programming error in Window | Preferences, PHP | Semantic Analysis.

    0 讨论(0)
  • 2020-12-11 03:39

    As you well know Zend Studio is built on eclipse, which is a Java IDE. In the Java language it's ilegal to do something like this:

    String s;
    while (s = getName()) {
        ...
    }
    

    That's because even if 'getName' returns a null value it will be assigned to 's' and casting between objects and booleans (which is the required type by the condition statements) is a bit more subjective as with PHP, therefore it will throw an exception in compile time.

    The situation in PHP may be different, but for some reason the Zend developers decided to leave this warning active by default, you can disable it as mentioned before but i consider it will help you when a real assignment in condition happens.

    Cleaning the warning is quite easy by just assigning the results and then comparing it like this:

    if (($result = $mysqli->query ( $query )) == true) {
    

    Instead of:

    if ($result = $mysqli->query ( $query )) {
    

    As you can see you don't need additional bunches of code.

    Anyway it is just a warning, you don't have to worry of them much.

    0 讨论(0)
提交回复
热议问题