diff --git a/Normalizer/ArrayDenormalizer.php b/Normalizer/ArrayDenormalizer.php index 65b1c2e82..19baa490c 100644 --- a/Normalizer/ArrayDenormalizer.php +++ b/Normalizer/ArrayDenormalizer.php @@ -46,7 +46,7 @@ public function denormalize($data, $type, $format = null, array $context = []) if (!\is_array($data)) { throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.'); } - if ('[]' !== substr($type, -2)) { + if (!str_ends_with($type, '[]')) { throw new InvalidArgumentException('Unsupported class: '.$type); } @@ -74,7 +74,7 @@ public function supportsDenormalization($data, $type, $format = null, array $con throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used.', __METHOD__)); } - return '[]' === substr($type, -2) + return str_ends_with($type, '[]') && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context); } diff --git a/Tests/Normalizer/AbstractObjectNormalizerTest.php b/Tests/Normalizer/AbstractObjectNormalizerTest.php index 273a42aac..d1c1d1cbe 100644 --- a/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -484,7 +484,7 @@ public function denormalize($data, $type, $format = null, array $context = []) */ public function supportsDenormalization($data, $type, $format = null, array $context = []): bool { - return '[]' === substr($type, -2) + return str_ends_with($type, '[]') && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context); } diff --git a/composer.json b/composer.json index 075896e47..324c30edf 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "require": { "php": ">=7.1.3", - "symfony/polyfill-ctype": "~1.8" + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php80": "^1.16" }, "require-dev": { "doctrine/annotations": "^1.10.4",