8000 bug #33948 [PropertyInfo] Respect property name case when guessing fr… · symfony/symfony@0065f75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0065f75

Browse files
committed
bug #33948 [PropertyInfo] Respect property name case when guessing from public method name (antograssiot)
This PR was merged into the 3.4 branch. Discussion ---------- [PropertyInfo] Respect property name case when guessing from public method name | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #32656 | License | MIT | Doc PR | Using camelCase, with an attribute `$aFooBar`, naming the getter/setter `getAFooBar()`/`setAFooBar()`, returns the property name as AFooBar instead of aFooBar. # Before Property name `'AFooBar'` # After Property name `'aFooBar'` as expected Commits ------- 843bb76 [PropertyInfo] Respect property name case when guessing from public method name
2 parents 1201085 + 843bb76 commit 0065f75

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public function getProperties($class, array $context = [])
103103
if (!$propertyName || isset($properties[$propertyName])) {
104104
continue;
105105
}
106-
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
107-
$propertyName = lcfirst($propertyName);
106+
if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) {
107+
$propertyName = $lowerCasedPropertyName;
108108
}
109109
$properties[$propertyName] = $propertyName;
110110
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public function testGetProperties()
5959
'123',
6060
'self',
6161
'realParent',
62+
'xTotals',
63+
'YT',
6264
'c',
6365
'd',
6466
'e',

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ class Dummy extends ParentDummy
9393
*/
9494
public $j;
9595

96+
/**
97+
* @var array
98+
*/
99+
private $xTotals;
100+
101+
/**
102+
* @var string
103+
*/
104+
private $YT;
105+
96106
/**
97107
* This should not be removed.
98108
*
@@ -166,4 +176,18 @@ public function setSelf(self $self)
166176
public function setRealParent(parent $realParent)
167177
{
168178
}
179+
180+
/**
181+
* @return array
182+
*/
183+
public function getXTotals()
184+
{
185+
}
186+
187+
/**
188+
* @return string
189+
*/
190+
public function getYT()
191+
{
192+
}
169193
}

0 commit comments

Comments
 (0)
0