Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfdac85

Browse files
committed
bug #21332 [PropertyInfo] Don't try to access a property thru a static method (dunglas)
This PR was merged into the 2.8 branch. Discussion ---------- [PropertyInfo] Don't try to access a property thru a static method | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a See also #21331. Commits ------- 3b4858f [PropertyInfo] Don't try to access a property thru a static method
2 parents 0ca3e96 + 3b4858f commit bfdac85

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ private function getDocBlockFromMethod($class, $ucFirstProperty, $type)
253253

254254
try {
255255
$reflectionMethod = new \ReflectionMethod($class, $methodName);
256+
if ($reflectionMethod->isStatic()) {
257+
continue;
258+
}
256259

257260
if (
258261
(self::ACCESSOR === $type && 0 === $reflectionMethod->getNumberOfRequiredParameters()) ||

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ private function getAccessorMethod($class, $property)
262262
foreach (self::$accessorPrefixes as $prefix) {
263263
try {
264264
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
265+
if ($reflectionMethod->isStatic()) {
266+
continue;
267+
}
265268

266269
if (0 === $reflectionMethod->getNumberOfRequiredParameters()) {
267270
return array($reflectionMethod, $prefix);
@@ -290,6 +293,9 @@ private function getMutatorMethod($class, $property)
290293
foreach (self::$mutatorPrefixes as $prefix) {
291294
try {
292295
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
296+
if ($reflectionMethod->isStatic()) {
297+
continue;
298+
}
293299

294300
// Parameter can be optional to allow things like: method(array $foo = null)
295301
if ($reflectionMethod->getNumberOfParameters() >= 1) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function typesProvider()
6868
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
6969
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
7070
array('donotexist', null, null, null),
71+
array('staticGetter', null, null, null),
72+
array('staticSetter', null, null, null),
7173
);
7274
}
7375
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function typesProvider()
7272
array('e', null),
7373
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')))),
7474
array('donotexist', null),
75+
array('staticGetter', null),
76+
array('staticSetter', null),
7577
);
7678
}
7779

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public static function getStatic()
5555
{
5656
}
5757

58+
/**
59+
* @return string
60+
*/
61+
public static function staticGetter()
62+
{
63+
}
64+
65+
public static function staticSetter(\DateTime $d)
66+
{
67+
}
68+
5869
/**
5970
* A.
6071
*

0 commit comments

Comments
 (0)