What does this ~ operator mean here?

前端 未结 5 1908
清酒与你
清酒与你 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条回答
  •  旧时难觅i
    2020-12-06 11:03

    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 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).

提交回复
热议问题