Skip to content

Commit c4513b7

Browse files
committed
Merge pull request #28 from graze/fix-php7
Fix JSON parsing in PHP 7
2 parents a94d2b2 + c943f3e commit c4513b7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ php:
1010

1111
matrix:
1212
allow_failures:
13-
- php: 7
1413
- php: hhvm
1514
fast_finish: true
1615

src/functions.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0)
4343
JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
4444
JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
4545
JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded',
46-
];
47-
$data = \json_decode($json, $assoc, $depth, $options);
46+
];
47+
48+
// Patched support for decoding empty strings for PHP 7+
49+
$data = \json_decode($json == "" ? "{}" : $json, $assoc, $depth, $options);
4850

4951
if (JSON_ERROR_NONE !== json_last_error()) {
5052
$last = json_last_error();

0 commit comments

Comments
 (0)