From 846116edab4dd510441e69c5218b7bdc8cdac89f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 5 Jun 2019 13:58:47 +0200 Subject: [PATCH] [HttpClient] revert bad logic around JSON_THROW_ON_ERROR --- src/Symfony/Component/HttpClient/HttpClientTrait.php | 8 +------- .../Component/HttpClient/Response/ResponseTrait.php | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpClient/HttpClientTrait.php b/src/Symfony/Component/HttpClient/HttpClientTrait.php index bea095134edf..2df830e11130 100644 --- a/src/Symfony/Component/HttpClient/HttpClientTrait.php +++ b/src/Symfony/Component/HttpClient/HttpClientTrait.php @@ -301,13 +301,7 @@ private static function jsonEncode($value, int $flags = null, int $maxDepth = 51 } try { - if (\PHP_VERSION_ID >= 70300) { - // Work around https://bugs.php.net/77997 - json_encode(null); - $flags |= JSON_THROW_ON_ERROR; - } - - $value = json_encode($value, $flags, $maxDepth); + $value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0), $maxDepth); } catch (\JsonException $e) { throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage())); } diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 79cc40d5d847..6b62b855360e 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -148,7 +148,7 @@ public function toArray(bool $throw = true): array } try { - $content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0)); + $content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0)); } catch (\JsonException $e) { throw new JsonException($e->getMessage(), $e->getCode()); }