diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 2e00fc2262317..c18d278688193 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -186,11 +186,6 @@ private function writeData(array $data, array $options) { $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) { - // Work around https://bugs.php.net/77997 - json_encode(null); - } - $this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n"); } diff --git a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php index 529fb82c4029f..f5a143800b27c 100644 --- a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php @@ -99,11 +99,6 @@ private function writeData(array $data, array $options) { $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) { - // Work around https://bugs.php.net/77997 - json_encode(null); - } - $this->write(json_encode($data, $flags)); } diff --git a/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php index 00a5425866b29..428586965ba64 100644 --- a/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php @@ -83,11 +83,6 @@ private function writeData(array $data, array $options) { $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) { - // Work around https://bugs.php.net/77997 - json_encode(null); - } - $this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n"); } diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 52f55f7486c97..24798eea42b32 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -153,11 +153,6 @@ public function setData($data = []) restore_error_handler(); } } else { - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) { - // Work around https://bugs.php.net/77997 - json_encode(null); - } - try { $data = json_encode($data, $this->encodingOptions); } catch (\Exception $e) { @@ -166,6 +161,10 @@ public function setData($data = []) } throw $e; } + + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) { + return $this->setJson($data); + } } } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index 1d0b86afc5d07..a55f1232e7e98 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -72,7 +72,15 @@ public function decode($data, $format, array $context = []) $recursionDepth = $context['json_decode_recursion_depth']; $options = $context['json_decode_options']; - $decodedData = json_decode($data, $associative, $recursionDepth, $options); + try { + $decodedData = json_decode($data, $associative, $recursionDepth, $options); + } catch (\JsonException $e) { + throw new NotEncodableValueException($e->getMessage(), 0, $e); + } + + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) { + return $decodedData; + } if (JSON_ERROR_NONE !== json_last_error()) { throw new NotEncodableValueException(json_last_error_msg()); diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index e5b48757dd0c2..76e532c4b7a34 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -36,13 +36,12 @@ public function encode($data, $format, array $context = []) { $context = $this->resolveContext($context); + $encodedJson = json_encode($data, $context['json_encode_options']); + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $context['json_encode_options'])) { - // Work around https://bugs.php.net/77997 - json_encode(null); + return $encodedJson; } - $encodedJson = json_encode($data, $context['json_encode_options']); - if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($context['json_encode_options'] & JSON_PARTIAL_OUTPUT_ON_ERROR))) { throw new NotEncodableValueException(json_last_error_msg()); } diff --git a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php index 2a8d23d477e21..3ee446dc73183 100644 --- a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php @@ -31,11 +31,6 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti $flags = \defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; } - if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $flags)) { - // Work around https://bugs.php.net/77997 - json_encode(null); - } - return json_encode($messages->all($domain), $flags); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: