Skip to content

Commit

Permalink
bug #31861 [HttpClient] work around PHP 7.3 bug related to json_encod…
Browse files Browse the repository at this point in the history
…e() (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()
  • Loading branch information
fabpot committed Jun 5, 2019
2 parents 04e2026 + 42904e3 commit 4f7c614
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Symfony/Component/HttpClient/HttpClientTrait.php
Expand Up @@ -301,7 +301,13 @@ private static function jsonEncode($value, int $flags = null, int $maxDepth = 51
}

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) {
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
}
Expand Down

0 comments on commit 4f7c614

Please sign in to comment.