Skip to content

Commit de8ddfd

Browse files
committed
bug #39896 [PropertyInfo] Fix breaking change with has*(arguments...) methods (YaFou)
This PR was merged into the 5.1 branch. Discussion ---------- [PropertyInfo] Fix breaking change with has*(arguments...) methods | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39885 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Until 5.0: ```php class Dummy { private $elements; public function hasElement($element): bool { // ... } } $extractor = new ReflectionExtractor(); $extractor->isReadable('Dummy', 'element'); // false ``` After 5.0: ```php class Dummy { private $elements; public function hasElement($element): bool { // ... } } $extractor = new ReflectionExtractor(); $extractor->isReadable('Dummy', 'element'); // true => BREAKING CHANGE ``` Commits ------- 37cc16e [PropertyInfo] Fix breaking change with has*(arguments...) methods
2 parents 2645226 + 37cc16e commit de8ddfd

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function getReadInfo(string $class, string $property, array $context = []
239239
foreach ($this->accessorPrefixes as $prefix) {
240240
$methodName = $prefix.$camelProp;
241241

242-
if ($reflClass->hasMethod($methodName) && ($reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags)) {
242+
if ($reflClass->hasMethod($methodName) && $reflClass->getMethod($methodName)->getModifiers() & $this->methodReflectionFlags && !$reflClass->getMethod($methodName)->getNumberOfRequiredParameters()) {
243243
$method = $reflClass->getMethod($methodName);
244244

245245
return new PropertyReadInfo(PropertyReadInfo::TYPE_METHOD, $methodName, $this->getReadVisiblityForMethod($method), $method->isStatic(), false);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testGetProperties()
7575
'xTotals',
7676
'YT',
7777
'date',
78+
'element',
7879
'c',
7980
'd',
8081
'e',
@@ -291,6 +292,7 @@ public function getReadableProperties()
291292
['id', true],
292293
['Guid', true],
293294
['guid', false],
295+
['element', false],
294296
];
295297
}
296298

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class Dummy extends ParentDummy
130130
*/
131131
public $nestedIterators;
132132

133+
private $elements;
134+
133135
public static function getStatic()
134136
{
135137
}
@@ -218,4 +220,8 @@ public function setDate(\DateTime $date)
218220
public function addDate(\DateTime $date)
219221
{
220222
}
223+
224+
public function hasElement(string $element): bool
225+
{
226+
}
221227
}

0 commit comments

Comments
 (0)