Created
          October 18, 2017 13:24 
        
      - 
      
- 
        Save CodeBrauer/565422e6c81f95c4de7275e5a4e85d0f to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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 | |
| // or just use json_last_error_msg... | |
| public function get_json_human_error($err_code) | |
| { | |
| $constants = get_defined_constants(true); | |
| $json_error_constants = array_filter(array_keys($constants['json']), function($row) { | |
| return strpos($row, 'JSON_ERROR_') !== false; | |
| }); | |
| foreach ($json_error_constants as $index => $error_name) { | |
| $json_error_constants[constant($error_name)] = $error_name; | |
| unset($json_error_constants[$index]); | |
| } | |
| return isset($json_error_constants[$err_code]) ? $json_error_constants[$err_code] : 'UNKNOWN_JSON_ERROR'; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment