[HttpClient] work around PHP 7.3 bug related to json_encode()

This commit is contained in:
Nicolas Grekas 2019-06-04 20:58:48 +02:00
parent 40076b98bf
commit 42904e34e6

View File

@ -301,7 +301,13 @@ trait HttpClientTrait
} }
try { try {
$value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth); 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);
} catch (\JsonException $e) { } catch (\JsonException $e) {
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage())); throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
} }