Skip to content
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

Fix infinite loop when indexing self referencing classes #670

Merged
merged 4 commits into from Nov 11, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions fixtures/self_referencing_class.php
@@ -0,0 +1,20 @@
<?php
namespace RecursiveTest;

class A extends A {}

class B extends C {}
class C extends B {}

class D extends E {}
class E extends F {}
class F extends D {}

$a = new A;
$a->undef_prop = 1;

$b = new B;
$b->undef_prop = 1;

$d = new D;
$d->undef_prop = 1;
8 changes: 7 additions & 1 deletion src/DefinitionResolver.php
Expand Up @@ -438,6 +438,7 @@ private function resolveMemberAccessExpressionNodeToFqn(Node\Expression\MemberAc

// Find the right class that implements the member
$implementorFqns = [$classFqn];
$visitedFqns = [];

while ($implementorFqn = array_shift($implementorFqns)) {
// If the member FQN exists, return it
Expand All @@ -450,10 +451,15 @@ private function resolveMemberAccessExpressionNodeToFqn(Node\Expression\MemberAc
if ($implementorDef === null) {
break;
}
// Note the FQN as visited
$visitedFqns[] = $implementorFqn;
// Repeat for parent class
if ($implementorDef->extends) {
foreach ($implementorDef->extends as $extends) {
$implementorFqns[] = $extends;
// Don't add the parent FQN if it's already been visited
if (!\in_array($extends, $visitedFqns)) {
$implementorFqns[] = $extends;
}
}
}
}
Expand Down