10000 [PropertyInfo] Don't try to access a property thru a static method by dunglas · Pull Request #21332 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyInfo] Don't try to access a property thru a static method #21332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[PropertyInfo] Don't try to access a property thru a static method
  • Loading branch information
dunglas committed Jan 18, 2017
commit 3b4858fe88814d820327bba46a00859a983d089e
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ private function getDocBlockFromMethod($class, $ucFirstProperty, $type)

try {
$reflectionMethod = new \ReflectionMethod($class, $methodName);
if ($reflectionMethod->isStatic()) {
continue;
}

if (
(self::ACCESSOR === $type && 0 === $reflectionMethod->getNumberOfRequiredParameters()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ private function getAccessorMethod($class, $property)
foreach (self::$accessorPrefixes as $prefix) {
try {
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
if ($reflectionMethod->isStatic()) {
continue;
}

if (0 === $reflectionMethod->getNumberOfRequiredParameters()) {
return array($reflectionMethod, $prefix);
Expand Down Expand Up @@ -286,6 +289,9 @@ private function getMutatorMethod($class, $property)
foreach (self::$mutatorPrefixes as $prefix) {
try {
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
if ($reflectionMethod->isStatic()) {
continue;
}

// Parameter can be optional to allow things like: method(array $foo = null)
if ($reflectionMethod->getNumberOfParameters() >= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function typesProvider()
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),
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),
array('donotexist', null, null, null),
array('staticGetter', null, null, null),
array('staticSetter', null, null, null),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function typesProvider()
array('e', null),
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')))),
array('donotexist', null),
array('staticGetter', null),
array('staticSetter', null),
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up 66D5 @@ -51,6 +51,17 @@ class Dummy extends ParentDummy
*/
public $B;

/**
* @return string
*/
public static function staticGetter()
{
}

public static function staticSetter(\DateTime $d)
{
}

/**
* A.
*
Expand Down
0