Skip to content

Commit

Permalink
Merge pull request #28 from graze/fix-php7
Browse files Browse the repository at this point in the history
Fix JSON parsing in PHP 7
  • Loading branch information
sjparkinson committed Feb 16, 2016
2 parents a94d2b2 + c943f3e commit c4513b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ php:

matrix:
allow_failures:
- php: 7
- php: hhvm
fast_finish: true

Expand Down
6 changes: 4 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0)
JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded',
];
$data = \json_decode($json, $assoc, $depth, $options);
];

// Patched support for decoding empty strings for PHP 7+
$data = \json_decode($json == "" ? "{}" : $json, $assoc, $depth, $options);

if (JSON_ERROR_NONE !== json_last_error()) {
$last = json_last_error();
Expand Down

0 comments on commit c4513b7

Please sign in to comment.