'AND' vs '&&' as operator

后端 未结 10 617
野性不改
野性不改 2020-11-22 02:42

I have a codebase where developers decided to use AND and OR instead of && and ||.

I know that there is a

10条回答
  •  自闭症患者
    2020-11-22 03:30

    Here's a little counter example:

    $a = true;
    $b = true;
    $c = $a & $b;
    var_dump(true === $c);
    

    output:

    bool(false)
    

    I'd say this kind of typo is far more likely to cause insidious problems (in much the same way as = vs ==) and is far less likely to be noticed than adn/ro typos which will flag as syntax errors. I also find and/or is much easier to read. FWIW, most PHP frameworks that express a preference (most don't) specify and/or. I've also never run into a real, non-contrived case where it would have mattered.

提交回复
热议问题