What does this ~ operator mean here?

Example:

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

what does that suppose to mean?


It is the bitwise not operator (also called "complement"). That is the bits set in ~ $a are those that are not set in $a .

So then

E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE

is the bits set in E_ALL and those not set in E_STRICT , E_WARNING and E_NOTICE . This basically says all errors except strict, warning and notice errors.


It's the bitwise-not operator. For example the bitwise negation of a number with binary representation 01011110 would be 10100001 ; every single bit is flipped to its opposite.


The distinction between bitwise (&, |, ~) and non-bitwise (&&, ||, !) operators is that bitwise are applied across all bits in the integer, while non-bitwise treat an integer as a single "true" (non-zero) or "false" (zero) value.

Say, $flag_1 = 00000001 and $flag_2 = 00000010 . Both would be "true" for non-bitwise operations, ( $flag_1 && $flag_2 is "true"), while the result of $flag_1 & $flag_2 would be 00000000 and the result of $flag_1 | $flag_2 $flag_1 | $flag_2 would be 00000011. ~$flag_2 would be 11111101, which when bitwise-ANDed to a running result would clear that bit position (xxxxxx0x). $flag_2 bitwise-ORed to a running result would set that bit position (xxxxxx1x).

链接地址: http://www.djcxy.com/p/1820.html

上一篇: PHP中的数组运算符?

下一篇: 这个〜操作符在这里表示什么?