Search code examples
phperror-reporting

PHP Error Reporting - use of "^" character and the "~" character


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

Solution

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