1
0
Fork 0
pull/567/merge
Phil Nelson 2017-12-29 02:51:40 +00:00 committed by GitHub
commit 675feef024
2 changed files with 24 additions and 2 deletions

View File

@ -38,3 +38,10 @@ foreach ($bar->test() as $value) {
foreach ($unknownArray as $member->access => $unknown) {
$unkno
}
foreach ($loop as $loop) {
}
foreach ($loop->getArray() as $loop) {
}

View File

@ -571,12 +571,27 @@ class DefinitionResolver
// If we get to a ForeachStatement, check the keys and values
if ($n instanceof Node\Statement\ForeachStatement) {
if ($n->foreachKey instanceof Node\Expression\Variable
// Only check keys and values if we did not get here from the foreach collection, otherwise code like
// foreach ($a as $a) will send us in circles
$isForeachCollection = false;
if ($n->forEachCollectionName) {
if ($n->forEachCollectionName === $var) {
$isForeachCollection = true;
} else {
foreach ($n->forEachCollectionName->getDescendantNodes() as $childNode) {
if ($childNode === $var) {
$isForeachCollection = true;
break;
}
}
}
}
if (!$isForeachCollection && $n->foreachKey instanceof Node\Expression\Variable
&& $n->foreachKey->expression->getName() === $name
) {
return $n->foreachKey;
}
if ($n->foreachValue
if (!$isForeachCollection && $n->foreachValue
&& $n->foreachValue->expression instanceof Node\Expression\Variable
&& $n->foreachValue->expression->getName() === $name
) {