Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PropertyInfo] Respect property name case when guessing from public method name #33948

Merged
merged 1 commit into from Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -103,8 +103,8 @@ public function getProperties($class, array $context = [])
if (!$propertyName || isset($properties[$propertyName])) {
continue;
}
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
$propertyName = lcfirst($propertyName);
if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) {
$propertyName = $lowerCasedPropertyName;
}
$properties[$propertyName] = $propertyName;
}
Expand Down
Expand Up @@ -59,6 +59,8 @@ public function testGetProperties()
'123',
'self',
'realParent',
'xTotals',
'YT',
'c',
'd',
'e',
Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Expand Up @@ -93,6 +93,16 @@ class Dummy extends ParentDummy
*/
public $j;

/**
* @var array
*/
private $xTotals;

/**
* @var string
*/
private $YT;

/**
* This should not be removed.
*
Expand Down Expand Up @@ -166,4 +176,18 @@ public function setSelf(self $self)
public function setRealParent(parent $realParent)
{
}

/**
* @return array
*/
public function getXTotals()
{
}

/**
* @return string
*/
public function getYT()
{
}
}