PHP错误报告 - 使用“^”字符和“〜”字符

I'm try to understand the difference between the use of the "^" character and the "~" character when setting the error_reporting values. For example I have the following in my php script:

if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
error_reporting(E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED & ~ E_NOTICE);
} else {
error_reporting(E_ALL ^ E_NOTICE);
}

I've read the manual page at:

http://php.net/manual/en/function.error-reporting.php

but I'm now more confused than ever. Is:

error_reporting(E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED & ~ E_NOTICE);

the same as:

error_reporting(E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED ^ E_NOTICE);

those are bitwise operators: http://php.net/manual/en/language.operators.bitwise.php

error_reporting(E_ALL & ~ E_DEPRECATED & ~ E_USER_DEPRECATED & ~ E_NOTICE);

would mean E_ALL and NOT E_DEPRECATED and NOT E_USER_DEPRECATED & NOT E_NOTICE

while

error_reporting(E_ALL ^ E_DEPRECATED ^ E_USER_DEPRECATED ^ E_NOTICE);

would mean E_ALL except E_DEP.... etc.

I think the more relevant answer to your question was listed in a comment on the error reporting page on php.net which I'll repost here:

The example of E_ALL ^ E_NOTICE is a 'bit' confusing for those of us not wholly conversant with bitwise operators.

If you wish to remove notices from the current level, whatever that unknown level might be, use & ~ instead:

<?php
//....
$errorlevel=error_reporting();
error_reporting($errorlevel & ~E_NOTICE);
//...code that generates notices
error_reporting($errorlevel);
//...
?>

^ is the xor (bit flipping) operator and would actually turn notices on if they were previously off (in the error level on its left). It works in the example because E_ALL is guaranteed to have the bit for E_NOTICE set, so when ^ flips that bit, it is in fact turned off. & ~ (and not) will always turn off the bits specified by the right-hand parameter, whether or not they were on or off.