Skip to content

Instantly share code, notes, and snippets.

@Great-Antique
Created November 19, 2020 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Great-Antique/1dfcc473932550a737cdf0afc9edb596 to your computer and use it in GitHub Desktop.
Save Great-Antique/1dfcc473932550a737cdf0afc9edb596 to your computer and use it in GitHub Desktop.
PHP error reporting decoder
#!/usr/bin/env php
<?php
// Found: https://stackoverflow.com/a/4678125
if (!isset($argv[1])) {
echo <<<EXAMPLE
There is error reporting provided.
Usage: phperrorreporting 22527
EXAMPLE;
exit(2);
}
$error_reporting_value = trim($argv[1]);
if (!is_numeric($error_reporting_value)) {
echo <<<EXAMPLE
Invalid error reporting.
EXAMPLE;
exit(3);
}
$error_reporting_value = (int)$error_reporting_value;
if ($error_reporting_value < 0) {
echo <<<EXAMPLE
Invalid error reporting.
EXAMPLE;
exit(4);
}
$constants = array(
"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_STRICT",
"E_RECOVERABLE_ERROR",
"E_DEPRECATED",
"E_USER_DEPRECATED",
"E_ALL"
);
$included = array();
$excluded = array();
foreach ($constants as $constant) {
$value = constant($constant);
if (($error_reporting_value & $value) === $value) {
$included[] = $constant;
} else {
$excluded[] = $constant;
}
}
echo "error reporting " . $error_reporting_value . PHP_EOL;
echo "includes " . implode(", ", $included) . PHP_EOL;
echo "excludes " . implode(", ", $excluded) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment