Skip to content

Commit

Permalink
bug #45531 [Serializer] Fix passing null to str_contains() (Erwin Dirks)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

[Serializer] Fix passing null to str_contains()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

In PHP 8.1 `null` isn't allowed so the check `str_contains` will fail because `$format` can be `null`

Commits
-------

da7d8c0 [Serializer] Fix passing null to str_contains()
  • Loading branch information
nicolas-grekas committed Feb 24, 2022
2 parents 75bf7fa + da7d8c0 commit 9a22b37
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -472,7 +472,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
// PHP's json_decode automatically converts Numbers without a decimal part to integers.
// To circumvent this behavior, integers are converted to floats when denormalizing JSON based formats and when
// a float is expected.
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && str_contains($format, JsonEncoder::FORMAT)) {
if (Type::BUILTIN_TYPE_FLOAT === $builtinType && \is_int($data) && null !== $format && str_contains($format, JsonEncoder::FORMAT)) {
return (float) $data;
}

Expand Down

0 comments on commit 9a22b37

Please sign in to comment.