[Validator] Ensure numeric subpaths do not cause errors on PHP 7.4

This commit is contained in:
Alex Pott 2019-10-24 10:11:33 +01:00 committed by Tobias Schultze
parent 5d097d2eb5
commit 6244a1ec47
2 changed files with 4 additions and 2 deletions

View File

@ -32,6 +32,7 @@ class PropertyPathTest extends TestCase
['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.'],
];
}
}

View File

@ -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;