Numeric values of error reporting levels

后端 未结 6 608
孤独总比滥情好
孤独总比滥情好 2020-12-24 09:14

I\'m checking the configuration of my PHP server and I need to set the following parameter as follows:

error_reporting set to E_ALL & ~E_NOTICE

相关标签:
6条回答
  • 2020-12-24 09:30

    error_reporting 6135 will not log Runtime Notices, So better to use

    error_reporting(E_ALL);
    

    followed by

    ini_set('display_errors', '0');
    

    This will log all errors including Runtime notices, But pevent displaying in browser. This can be used in any PHP versions.

    0 讨论(0)
  • 2020-12-24 09:36

    Note, that error_reporting(-1); will report all and any PHP errors.

    0 讨论(0)
  • 2020-12-24 09:46

    Values used for error reporting

     E_RECOVERABLE_ERROR  4096 +
    E_USER_NOTICE        1024 +
    E_USER_WARNING        512 +
    E_USER_ERROR          256 +
    E_COMPILE_WARNING     128 +
    E_COMPILE_ERROR        64 +
    E_CORE_WARNING         32 +
    E_CORE_ERROR           16 +
    E_PARSE                 4 +
    E_WARNING               2 +
    E_ERROR                 1 +
                       = 6135
    
    0 讨论(0)
  • 2020-12-24 09:50
    foreach(
        array('E_ALL', 'E_NOTICE', '~E_NOTICE', 'E_ALL&~E_NOTICE') 
        as $s) {
        eval("\$v=$s;");
        printf("%20s = dec %10u = bin %32b\n", $s, $v, $v);
    }
    

    result

               E_ALL = dec       6143 = bin                    1011111111111
            E_NOTICE = dec          8 = bin                             1000
           ~E_NOTICE = dec 4294967287 = bin 11111111111111111111111111110111
     E_ALL&~E_NOTICE = dec       6135 = bin                    1011111110111
    
    0 讨论(0)
  • 2020-12-24 09:51

    The error flags are power of 2 integers so you can combine them using bit operators. The result is an integer like the one you see so if you set it to E_ALL & ~E_NOTICE it will still end up as integer. What flags comprise the 6135 value depends on your php version. You can check if a flag is contained within it using the bitwise and operator, e.g.

    if ((error_reporting() & E_NOTICE) == E_NOTICE) {
        echo "E_NOTICE is active";
    }
    
    0 讨论(0)
  • 2020-12-24 09:55

    From the page we have:

    • E_ALL has the value 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously

    • E_NOTICE has the value 8

    Looks like you are using PHP 5.2.x

    Now If you do E_ALL & ~E_NOTICE Which is bitwise complement of E_NOTICE followed by bitwise anding with E_ALL we get

    6143 & (~8) = 6135
    
    0 讨论(0)
提交回复
热议问题