What does this ~ operator mean here?

前端 未结 5 1853
清酒与你
清酒与你 2020-12-06 10:54

Example:

set_error_handler(array($this, \'handleError\'), E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);

what does that suppose t

5条回答
  •  [愿得一人]
    2020-12-06 11:16

    See Bitwise Operators : it's the "not" operator (quoting) :

    ~ $a
    Bits that are set in $a are not set, and vice versa.


    Which means, taking an example inspired from what you posted, that this portion of code :

    var_dump(decbin(E_STRICT));
    var_dump(decbin(~E_STRICT));
    

    Will get you this output :

    string '100000000000' (length=12)
    string '11111111111111111111011111111111' (length=32)
    

    (Add a couple of 0 for padding on the left of the first line, and you'll see what I mean)


    Removing the padding from the second output, you get :

    100000000000
    011111111111
    

    Which means the ~ operator gave a 0 bit for each bit that was equal to 1 in the intput -- and vice-versa,

提交回复
热议问题