Skip to content

Commit

Permalink
Manage JSON_THROW_ON_ERROR conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneroudeix committed Dec 14, 2020
1 parent a8ab087 commit c36263e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/special_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
*/
function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0)
{
if ($options & 4194304) { // options has JSON_THROW_ON_ERROR
try {
$data = \json_decode($json, $assoc, $depth, $options);
} catch (\Exception $e) {
throw new JsonException($e->getMessage(), (int) $e->getCode());
}
return $data;
}

$data = \json_decode($json, $assoc, $depth, $options);
if (JSON_ERROR_NONE !== json_last_error()) {
throw JsonException::createFromPhpError();
Expand Down

0 comments on commit c36263e

Please sign in to comment.