Skip to content

Commit

Permalink
bug #22426 [PropertyInfo] Prevent returning int values in some cases …
Browse files Browse the repository at this point in the history
…(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.
  • Loading branch information
fabpot committed Apr 13, 2017
2 parents d564c6a + b190ec2 commit f3eaa78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Expand Up @@ -64,7 +64,7 @@ public function getProperties($class, array $context = array())

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

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

return array_keys($properties);
return array_values($properties);
}

/**
Expand Down
Expand Up @@ -32,7 +32,7 @@ protected function setUp()

public function testGetProperties()
{
$this->assertEquals(
$this->assertSame(
array(
'bal',
'parent',
Expand All @@ -49,6 +49,7 @@ public function testGetProperties()
'a',
'DOB',
'Id',
'123',
'c',
'd',
'e',
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Expand Up @@ -116,4 +116,8 @@ public function getDOB()
public function getId()
{
}

public function get123()
{
}
}

0 comments on commit f3eaa78

Please sign in to comment.