Skip to content

Commit f3eaa78

Browse files
committed
bug symfony#22426 [PropertyInfo] Prevent returning int values in some cases (dunglas)
This PR was merged into the 2.8 branch. Discussion ---------- [PropertyInfo] Prevent returning int values in some cases | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | api-platform/api-platform#282, api-platform/core#1055 | License | MIT | Doc PR | n/a PHP automatically converts array keys to an int if and only if it looks like an int... When a getter looks like `get123`, the ReflectionExtractor returns an array containing an int instead of a string. This PR fixes this. Commits ------- b190ec2 [PropertyInfo] Prevent returning int values in some cases.
2 parents d564c6a + b190ec2 commit f3eaa78

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getProperties($class, array $context = array())
6464

6565
$properties = array();
6666
foreach ($reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflectionProperty) {
67-
$properties[$reflectionProperty->name] = true;
67+
$properties[$reflectionProperty->name] = $reflectionProperty->name;
6868
}
6969

7070
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
@@ -79,10 +79,10 @@ public function getProperties($class, array $context = array())
7979
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
8080
$propertyName = lcfirst($propertyName);
8181
}
82-
$properties[$propertyName] = true;
82+
$properties[$propertyName] = $propertyName;
8383
}
8484

85-
return array_keys($properties);
85+
return array_values($properties);
8686
}
8787

8888
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp()
3232

3333
public function testGetProperties()
3434
{
35-
$this->assertEquals(
35+
$this->assertSame(
3636
array(
3737
'bal',
3838
'parent',
@@ -49,6 +49,7 @@ public function testGetProperties()
4949
'a',
5050
'DOB',
5151
'Id',
52+
'123',
5253
'c',
5354
'd',
5455
'e',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@ public function getDOB()
116116
public function getId()
117117
{
118118
}
119+
120+
public function get123()
121+
{
122+
}
119123
}

0 commit comments

Comments
 (0)