Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this ~ operator mean here?

Tags:

php

Example:

set_error_handler(array($this, 'handleError'), E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);

what does that suppose to mean?

like image 525
openfrog Avatar asked Dec 27 '09 23:12

openfrog


2 Answers

It is the bitwise not operator (also called "complement"). That is the bits set in ~ $a are those that are not set in $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.

like image 147
jason Avatar answered Oct 07 '22 15:10

jason


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.

like image 41
sth Avatar answered Oct 07 '22 14:10

sth