PHP Error Reporting Levels – WTF is 6134?
In PHP, the error reporting level (whether errors go to the log or to the screen or whatever) is determinded by the error_reporting INI directive (or at runtime using the error_reporting() function). Both take an integer as their value - and usually this integer is represented by error level constants like E_ALL, E_STRICT or E_USER_WARNING.
So in order to set the error reporting to anything but notices and strict errors, you would set something like this in php.ini:
-
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
(actually, E_ALL does not really include E_STRICT but I put it here just to be more explicit)
This is actually great - one of the more easy to use and understand APIs in my opinion (yeah, I really like bitwise operations).
However, what I really hate is that sometimes I need to work with the integer value of the error reporting level (like 1 for E_ERROR or 84 for E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR) and it's very hard for me to remember what arbitrary numbers like 6134 mean.
So, today I wrote this tiny CLI script that helps me understand what an arbitrary error_reporting level integer might mean:
-
<?php
-
-
$errorLevels = array(
-
'E_COMPILE_ERROR' => E_COMPILE_ERROR,
-
'E_COMPILE_WARNING' => E_COMPILE_WARNING,
-
'E_CORE_ERROR' => E_CORE_ERROR,
-
'E_CORE_WARNING' => E_CORE_WARNING,
-
'E_ERROR' => E_ERROR,
-
'E_NOTICE' => E_NOTICE,
-
'E_PARSE' => E_PARSE,
-
'E_RECOVERABLE_ERROR' => E_RECOVERABLE_ERROR,
-
'E_STRICT' => E_STRICT,
-
'E_USER_ERROR' => E_USER_ERROR,
-
'E_USER_NOTICE' => E_USER_NOTICE,
-
'E_USER_WARNING' => E_USER_WARNING,
-
'E_WARNING' => E_WARNING,
-
);
-
-
if (! isset($_SERVER['argv'][1])) {
-
fprintf(STDERR, "Usage: {$_SERVER['argv'][0]} <error_level>\n" .
-
" Where <error_level> is a PHP error reporting level\n");
-
exit(1);
-
}
-
-
$level = $_SERVER['argv'][1];
-
-
echo "Error level $level includes:\n";
-
foreach ($errorLevels as $k => $v) {
-
if ($level & $v) echo "\t $k \n";
-
}
-
-
echo "\n";
To use, just run the script with a single value parameter, like so:
-
shahar.e@wintergreen ~ $ php error_level.php 6134
-
Error level 6134 includes:
-
E_COMPILE_ERROR
-
E_COMPILE_WARNING
-
E_CORE_ERROR
-
E_CORE_WARNING
-
E_PARSE
-
E_RECOVERABLE_ERROR
-
E_USER_ERROR
-
E_USER_NOTICE
-
E_USER_WARNING
-
E_WARNING
Enjoy!
















I appreciate the fact the script makes no assumption on numerical values of the constants and on the order of them. I probably would have made the error of basing the script on % operator...