From 6244a1ec47034820f3dc0feb52ac4d3d8b13a8b6 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 24 Oct 2019 10:11:33 +0100 Subject: [PATCH] [Validator] Ensure numeric subpaths do not cause errors on PHP 7.4 --- .../Component/Validator/Tests/Util/PropertyPathTest.php | 1 + src/Symfony/Component/Validator/Util/PropertyPath.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php b/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php index f796463bbc32..99bf9e6eb2eb 100644 --- a/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php @@ -32,6 +32,7 @@ public function provideAppendPaths() ['foo', 'bar', 'foo.bar', 'It append the subPath to the basePath'], ['foo', '[bar]', 'foo[bar]', 'It does not include the dot separator if subPath uses the array notation'], ['0', 'bar', '0.bar', 'Leading zeros are kept.'], + ['0', 1, '0.1', 'Numeric subpaths do not cause PHP 7.4 errors.'], ]; } } diff --git a/src/Symfony/Component/Validator/Util/PropertyPath.php b/src/Symfony/Component/Validator/Util/PropertyPath.php index 4108a02c24f2..5d062356772c 100644 --- a/src/Symfony/Component/Validator/Util/PropertyPath.php +++ b/src/Symfony/Component/Validator/Util/PropertyPath.php @@ -36,12 +36,13 @@ class PropertyPath */ public static function append($basePath, $subPath) { - if ('' !== (string) $subPath) { + $subPath = (string) $subPath; + if ('' !== $subPath) { if ('[' === $subPath[0]) { return $basePath.$subPath; } - return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath; + return '' !== $basePath ? $basePath.'.'.$subPath : $subPath; } return $basePath;