Skip to content

Commit eaa78d2

Browse files
[HttpClient] work around PHP 7.3 bug related to json_encode()
1 parent 5572012 commit eaa78d2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

HttpClientTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ private static function jsonEncode($value, int $flags = null, int $maxDepth = 51
301301
}
302302

303303
try {
304-
$value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth);
304+
if (\PHP_VERSION_ID >= 70300) {
305+
// Work around https://bugs.php.net/77997
306+
json_encode(null);
307+
$flags |= JSON_THROW_ON_ERROR;
308+
}
309+
310+
$value = json_encode($value, $flags, $maxDepth);
305311
} catch (\JsonException $e) {
306312
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
307313
}

0 commit comments

Comments
 (0)