Skip to content

Commit 16b7548

Browse files
author
Kyra Farrow
committed
[HttpClient] work around PHP 7.3 bug related to json_encode()
1 parent efdb0b5 commit 16b7548

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)