8000 [Serializer] Fix for method named `get()` · symfony/symfony@a0d6e26 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0d6e26

Browse files
mihai-stancunicolas-grekas
authored andcommitted
[Serializer] Fix for method named get()
1 parent 5df912c commit a0d6e26

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,19 @@ protected function extractAttributes(object $object, ?string $format = null, arr
100100
$name = $reflMethod->name;
101101
$attributeName = null;
102102

103-
if (str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can')) {
103+
if (3 < \strlen($name) && match ($name[0]) {
104+
'g' => str_starts_with($name, 'get'),
105+
'h' => str_starts_with($name, 'has'),
106+
'c' => str_starts_with($name, 'can'),
107+
default => false,
108+
}) {
104109
// getters, hassers and canners
105110
$attributeName = substr($name, 3);
106111

107112
if (!$reflClass->hasProperty($attributeName)) {
108113
$attributeName = lcfirst($attributeName);
109114
}
110-
} elseif (str_starts_with($name, 'is')) {
115+
} elseif ('is' !== $name && str_starts_with($name, 'is')) {
111116
// issers
112117
$attributeName = substr($name, 2);
113118

0 commit comments

Comments
 (0)
0