Skip to content

Commit 9d8be5c

Browse files
committed
Added polyfill for json_last_error_msg.
1 parent 3580460 commit 9d8be5c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"ext-curl": "*"
2929
},
3030
"autoload": {
31-
"psr-0": { "Bitbucket\\": "lib/" }
31+
"psr-0": { "Bitbucket\\": "lib/" },
32+
"files": ["polyfill-55.php"]
3233
},
3334
"scripts": {
3435
"test": "vendor/bin/phpunit"

polyfill-55.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright 2015 - 2016 Alexandru Guzinschi <alex@gentle.ro>
4+
*
5+
* This software may be modified and distributed under the terms
6+
* of the MIT license. See the LICENSE file for details.
7+
*/
8+
9+
/**
10+
* Provides functions unavailable in PHP releases prior to v5.5
11+
*/
12+
if (PHP_VERSION_ID < 50500) {
13+
if (!function_exists('json_last_error_msg')) {
14+
function json_last_error_msg()
15+
{
16+
switch (json_last_error()) {
17+
case JSON_ERROR_NONE:
18+
return 'No error';
19+
case JSON_ERROR_DEPTH:
20+
return 'Maximum stack depth exceeded';
21+
case JSON_ERROR_STATE_MISMATCH:
22+
return 'State mismatch (invalid or malformed JSON)';
23+
case JSON_ERROR_CTRL_CHAR:
24+
return 'Control character error, possibly incorrectly encoded';
25+
case JSON_ERROR_SYNTAX:
26+
return 'Syntax error';
27+
case JSON_ERROR_UTF8:
28+
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
29+
default:
30+
return 'Unknown error';
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)