mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fallback implementation of json_last_error_msg
This commit is contained in:
parent
bcb6549565
commit
10cfb878be
2 changed files with 24 additions and 2 deletions
|
@ -150,9 +150,9 @@ class JsonView extends View {
|
|||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=') && Configure::read('debug')) {
|
||||
$json = @json_encode($data, JSON_PRETTY_PRINT);
|
||||
$json = json_encode($data, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$json = @json_encode($data);
|
||||
$json = json_encode($data);
|
||||
}
|
||||
|
||||
if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) {
|
||||
|
|
|
@ -1061,3 +1061,25 @@ if (!function_exists('convertSlash')) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
if (!function_exists('json_last_error_msg')) {
|
||||
|
||||
/**
|
||||
* Provides the fallback implementation of json_last_error_msg() available in PHP 5.5 and above.
|
||||
*
|
||||
* @return string Error message.
|
||||
*/
|
||||
function json_last_error_msg() {
|
||||
static $errors = array(
|
||||
JSON_ERROR_NONE => '',
|
||||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
|
||||
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
|
||||
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
|
||||
JSON_ERROR_SYNTAX => 'Syntax error',
|
||||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
|
||||
);
|
||||
$error = json_last_error();
|
||||
return array_key_exists($error, $errors) ? $errors[$error] : "Unknown error ({$error})";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue