Last active
March 25, 2022 09:45
-
-
Save BenMorel/15878add393617a36486fbcb48805b71 to your computer and use it in GitHub Desktop.
Returns constants matching an error level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Examples: | |
* | |
* errorLevelToConstants(E_WARNING) => ['E_WARNING', 'E_ALL'] | |
* errorLevelToConstants(3) => ['E_ERROR', 'E_WARNING', 'E_ALL'] | |
* | |
* @return string[] | |
*/ | |
function errorLevelToConstants(int $level): array | |
{ | |
$constants = []; | |
foreach (get_defined_constants() as $constant => $value) { | |
if (str_starts_with($constant, 'E_')) { | |
if (($level & $value) !== 0) { | |
$constants[] = $constant; | |
} | |
} | |
} | |
return $constants; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment