Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created October 18, 2017 13:24
Show Gist options
  • Save CodeBrauer/565422e6c81f95c4de7275e5a4e85d0f to your computer and use it in GitHub Desktop.
Save CodeBrauer/565422e6c81f95c4de7275e5a4e85d0f to your computer and use it in GitHub Desktop.
<?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