Home / Work out PHP’s error reporting from an integer value

Work out PHP’s error reporting from an integer value

This post has some example PHP code which can be used to work out which error_reporting levels are reported and which are not from an integer value.

PHP code

Either use the $error = error_reporting() line to work out the error reporting levels for the current setting, or use a hard-coded value, replacing 22527 in the example code with the value you want to decode. Replace n with <br> tags if it’s being rendered on a webpage, or save the output to a variable if writing to file or emailing etc.

//$error = error_reporting();
$error = 22527;

$levels = array(
	E_ERROR => "E_ERROR",
	E_WARNING => "E_WARNING",
	E_PARSE => "E_PARSE",
	E_NOTICE => "E_NOTICE",
	E_CORE_ERROR => "E_CORE_ERROR",
	E_CORE_WARNING => "E_CORE_WARNING",
	E_COMPILE_ERROR => "E_COMPILE_ERROR",
	E_COMPILE_WARNING => "E_COMPILE_WARNING",
	E_USER_ERROR => "E_USER_ERROR",
	E_USER_WARNING => "E_USER_WARNING",
	E_USER_NOTICE => "E_USER_NOTICE",
	E_STRICT => "E_STRICT",
	E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
	E_DEPRECATED => "E_DEPRECATED",
	E_USER_DEPRECATED => "E_USER_DEPRECATED"
);

echo "Report on:n";
foreach ($levels as $level => $description) {
	if ($level & $error) {
		echo "$descriptionn";
	}
}

echo "n";

echo "Do not report on:n";
foreach ($levels as $level => $description) {
	if ($level & ~$error) {
		echo "$descriptionn";
	}
}

Example output

Report on:
E_ERROR
E_WARNING
E_PARSE
E_NOTICE
E_CORE_ERROR
E_CORE_WARNING
E_COMPILE_ERROR
E_COMPILE_WARNING
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
E_RECOVERABLE_ERROR
E_USER_DEPRECATED

Do not report on:
E_STRICT
E_DEPRECATED