Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON parsing in PHP 7 #28

Merged
merged 3 commits into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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