Example:
set_error_handler(array($this, 'handleError'), E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);
what does that suppose to mean?
这意味着什么?
5 个解决方案
#1
21
It is the bitwise not operator (also called "complement"). That is the bits set in ~ $a
are those that are not set in $a
.
它是按位非运算符(也称为“补码”)。也就是说〜$ a中设置的位是未在$ 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.
是E_ALL中设置的位以及未在E_STRICT,E_WARNING和E_NOTICE中设置的位。这基本上表示除严格,警告和通知错误之外的所有错误。
#2
16
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.
这是bitwise-not运算符。例如,具有二进制表示01011110的数字的按位否定将是10100001;每一位都翻转到相反的位置。
#3
6
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.
按位(&,|,〜)和非按位(&&,||,!)运算符之间的区别在于,按位应用于整数中的所有位,而非按位则将整数视为单个“true”(非零)或“假”(零)值。
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).
比如说,$ flag_1 = 00000001和$ flag_2 = 00000010.对于非按位操作,两者都是“true”,($ flag_1 && $ flag_2是“true”),而$ flag_1和$ flag_2的结果将是00000000并且$ flag_1 |的结果$ flag_2将是00000011.~ $ flag_2将是11111101,当按位与运行结果进行AND运算将清除该位位置(xxxxxx0x)。 $ flag_2按位或运算结果将设置该位位置(xxxxxx1x)。
#4
1
See Bitwise Operators : it's the "not" operator (quoting) :
请参阅按位运算符:它是“非”运算符(引用):
~ $a
Bits that are set in$a
are not set, and vice versa.〜$ a未设置$ a中设置的位,反之亦然。
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)
(在第一行的左边添加几个0用于填充,你会看到我的意思)
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,
这意味着〜运算符为每个在输入中等于1的位赋予0位 - 反之亦然,
#5
1
It's the not
bitwise operator. Read about bitwise operators here:
这不是按位运算符。阅读有关位运算符的信息:
#1
21
It is the bitwise not operator (also called "complement"). That is the bits set in ~ $a
are those that are not set in $a
.
它是按位非运算符(也称为“补码”)。也就是说〜$ a中设置的位是未在$ 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.
是E_ALL中设置的位以及未在E_STRICT,E_WARNING和E_NOTICE中设置的位。这基本上表示除严格,警告和通知错误之外的所有错误。
#2
16
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.
这是bitwise-not运算符。例如,具有二进制表示01011110的数字的按位否定将是10100001;每一位都翻转到相反的位置。
#3
6
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.
按位(&,|,〜)和非按位(&&,||,!)运算符之间的区别在于,按位应用于整数中的所有位,而非按位则将整数视为单个“true”(非零)或“假”(零)值。
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).
比如说,$ flag_1 = 00000001和$ flag_2 = 00000010.对于非按位操作,两者都是“true”,($ flag_1 && $ flag_2是“true”),而$ flag_1和$ flag_2的结果将是00000000并且$ flag_1 |的结果$ flag_2将是00000011.~ $ flag_2将是11111101,当按位与运行结果进行AND运算将清除该位位置(xxxxxx0x)。 $ flag_2按位或运算结果将设置该位位置(xxxxxx1x)。
#4
1
See Bitwise Operators : it's the "not" operator (quoting) :
请参阅按位运算符:它是“非”运算符(引用):
~ $a
Bits that are set in$a
are not set, and vice versa.〜$ a未设置$ a中设置的位,反之亦然。
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)
(在第一行的左边添加几个0用于填充,你会看到我的意思)
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,
这意味着〜运算符为每个在输入中等于1的位赋予0位 - 反之亦然,
#5
1
It's the not
bitwise operator. Read about bitwise operators here:
这不是按位运算符。阅读有关位运算符的信息: