Skip to content

Commit 3b4858f

Browse files
committed
[PropertyInfo] Don't try to access a property thru a static method
1 parent e18281e commit 3b4858f

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
@@ -258,6 +258,9 @@ private function getAccessorMethod($class, $property)
258258
foreach (self::$accessorPrefixes as $prefix) {
259259
try {
260260
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
261+
if ($reflectionMethod->isStatic()) {
262+
continue;
263+
}
261264

262265
if (0 === $reflectionMethod->getNumberOfRequiredParameters()) {
263266
return array($reflectionMethod, $prefix);
@@ -286,6 +289,9 @@ private function getMutatorMethod($class, $property)
286289
foreach (self::$mutatorPrefixes as $prefix) {
287290
try {
288291
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
292+
if ($reflectionMethod->isStatic()) {
293+
continue;
294+
}
289295

290296
// Parameter can be optional to allow things like: method(array $foo = null)
291297
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
@@ -51,6 +51,17 @@ class Dummy extends ParentDummy
5151
*/
5252
public $B;
5353

54+
/**
55+
* @return string
56+
*/
57+
public static function staticGetter()
58+
{
59+
}
60+
61+
public static function staticSetter(\DateTime $d)
62+
{
63+
}
64+
5465
/**
5566
* A.
5667
*

0 commit comments

Comments
 (0)