Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpClient] revert bad logic around JSON_THROW_ON_ERROR #31871

Merged
merged 1 commit into from Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/Symfony/Component/HttpClient/HttpClientTrait.php
Expand Up @@ -301,13 +301,7 @@ private static function jsonEncode($value, int $flags = null, int $maxDepth = 51
}

try {
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);
$value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0), $maxDepth);
} catch (\JsonException $e) {
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
}
Expand Down
Expand Up @@ -148,7 +148,7 @@ public function toArray(bool $throw = true): array
}

try {
$content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0));
$content = json_decode($content, true, 512, JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the added \ should allow the compiler to inline the check :)

} catch (\JsonException $e) {
throw new JsonException($e->getMessage(), $e->getCode());
}
Expand Down