Uppercase Booleans vs. Lowercase in PHP

后端 未结 11 2079
无人共我
无人共我 2020-12-23 02:33

When I was learning PHP, I read somewhere that you should always use the upper case versions of booleans, TRUE and FALSE, because the \"normal\" lo

11条回答
  •  无人及你
    2020-12-23 03:01

    It doesn't matter, true is exactly the same as TRUE. Same goes for false and null. I haven't heard that it would have mattered at any point.

    The only way you can mess things up is by quoting those values, for example:

    $foo = false;   // FALSE
    $bar = "false"; // TRUE
    
    $foo2 = true;   // TRUE
    $bar2 = "true"; // TRUE
    
    $foo3 = null;   // NULL
    $bar3 = "null"; // TRUE
    

    Only thing restricting or encouraging you to use upper or lowercase might be your company's or your own coding guidelines. Other than that, you're free to use either one and it will not lead in any issues.

提交回复
热议问题