Uppercase Booleans vs. Lowercase in PHP

后端 未结 11 1947
无人共我
无人共我 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:14

    Here is my TEST on Windows 7x64bit Apache/2.4.9 PHP/5.5.14

    $blockLimit = 50;
    while($blockLimit > 0): $blockLimit--;
    
    //STAR Here ================================================
    
    $msc = microtime(true);
    for ($i = 0; $i < 100000; $i++) {
       echo (FALSE);
    }
    echo 'FALSE took ' . number_format(microtime(true)-$msc,4) . " Seconds\r\n";
    $msc = microtime(true);
    for ($i = 0; $i < 100000; $i++) {
       echo (false);
    }
    echo 'false took ' . number_format(microtime(true)-$msc,4) . " Seconds\r\n";
    
    echo "\r\n --- \r\n";
    //Shutdown ==================================================
    endwhile;
    

    This time FALSE won 20 times. So uppercase is faster in my environment.

提交回复
热议问题