Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f7c614

Browse files
committed
bug #31861 [HttpClient] work around PHP 7.3 bug related to json_encode() (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] work around PHP 7.3 bug related to json_encode() | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This is the remaining of ##31860 for upper branches. Commits ------- 42904e3 [HttpClient] work around PHP 7.3 bug related to json_encode()
2 parents 04e2026 + 42904e3 commit 4f7c614

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Symfony/Component/HttpClient/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)