Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 683
user982124 Avatar asked Dec 08 '25 06:12

user982124


1 Answers

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.

like image 102
kennypu Avatar answered Dec 10 '25 20:12

kennypu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!