diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 6b05612ff53d..2e00fc226231 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -185,6 +185,12 @@ protected function describeContainerParameter($parameter, array $options = []) 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 197b843d4b76..529fb82c4029 100644 --- a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php @@ -97,7 +97,14 @@ protected function describeApplication(Application $application, array $options */ private function writeData(array $data, array $options) { - $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0)); + $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 ab518dbfeed1..00a5425866b2 100644 --- a/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Form/Console/Descriptor/JsonDescriptor.php @@ -82,6 +82,12 @@ protected function describeOption(OptionsResolver $optionsResolver, array $optio 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 6fb32ee41bda..52f55f7486c9 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -153,6 +153,11 @@ 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) { diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 9b07d709b8cf..e5b48757dd0c 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -36,6 +36,11 @@ public function encode($data, $format, array $context = []) { $context = $this->resolveContext($context); + if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $context['json_encode_options'])) { + // Work around https://bugs.php.net/77997 + json_encode(null); + } + $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))) { diff --git a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php index 3ee446dc7318..2a8d23d477e2 100644 --- a/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/JsonFileDumper.php @@ -31,6 +31,11 @@ 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); }