Convert error_reporting value constants into human-readable form:

I wanted to work out which errors were being logged given the error_reporting value from a php.ini file, so I spent 10 minutes writing this: (code below)

Error reporting value: Human readable format:

and here’s the code:

jQuery(document).ready(function($){
    function convert_error_constant_to_human_readable( value ) {
       var errors = {
        1: 'E_ERROR',
        2: 'E_WARNING',
        4: 'E_PARSE',
        8: 'E_NOTICE',
        16: 'E_CORE_ERROR',
        32: 'E_CORE_WARNING',
        64: 'E_COMPILE_ERROR',
        128: 'E_COMPILE_WARNING',
        256: 'E_USER_ERROR',
        512: 'E_USER_WARNING',
        1024: 'E_USER_NOTICE',      
        2048: 'E_STRICT',
        4096: 'E_RECOVERABLE_ERROR',
       }
       var human_readable_errors = [];
       for (var error in errors) {
         if (errors.hasOwnProperty(error)) {
           if ( value >= error && (value - error) % ( 2 * error) == 0 ) {
               var value = value - error;
               human_readable_errors.push( errors[error] );
           }
         }
       }
       return human_readable_errors;
    }
    $('#convert-to-human-readable').on( 'click', function(){
        var value = $('#error-reporting').val();
        var human_readable = convert_error_constant_to_human_readable( value );
        $('#human-readable').val( human_readable.join("\n") );
    });
});