-1 is also semantically meaningless as a bit field, and only works in 2s-complement numeric representations. On a 1s-complement system -1 would not set E_ERROR. On a sign-magnitude system -1 would set nothing at all! (see e.g. http://en.wikipedia.org/wiki/Ones%27_complement)

If you want to set all bits, ~0 is the correct way to do it.

But setting undefined bits could result in undefined behaviour and that means *absolutely anything* could happen :-)

I saw that Chris seems to think that errors might be combined in some cases, I don't know of any cases, but his code is overly verbose, inefficient, and doesn't take into account future E_ constants. Here's my version of handling multiple errors (which probably wont ever happen) using my other code as a base. The only real difference is that this doesn't bother to split out undefined bits, which is pretty much useless and would get rather messy if you have more than a few bits set above 2**14 (0 to 14 have an associated error).

I use this code to help mimic the default error handler, the only difference is that the levels end up being all caps, which I don't care to fix. You could also get rid of the underscores, but again, I don't care :PUntil php starts adding constants starting with E_ that have values overlapping with other E_ constants, this seems to be the shortest way of converting error code integers to strings understandable by meat bags. It will also work with new types, so that's nice.<?phpfunction friendly_error_type($type) { static $levels=null; if ($levels===null) {$levels=[]; foreach (get_defined_constants() as $key=>$value) { if (strpos($key,'E_')!==0) {continue;}$levels[$value]=substr($key,2); } } return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");}echo friendly_error_type(1); #ERRORecho friendly_error_type(2); #WARNINGecho friendly_error_type(3); #Error #3?>Tested on 5.6.12 and 7.0.3 (The first was by accident, didn't realize I was sshed into production :3)