Skip to content

Commit 1cfba8b

Browse files
phil-nelsonfelixfbecker
authored andcommitted
fix(DefinitionResolver): don't crash if foreach key isn't a variable (#564)
1 parent 425b239 commit 1cfba8b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

fixtures/completion/foreach.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ public function test() { }
3636
$
3737
}
3838

39-
foreach ($unknownArray as $unknown) {
39+
foreach ($unknownArray as $member->access => $unknown) {
4040
$unkno

src/DefinitionResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,9 @@ public function resolveVariableToNode($var)
571571

572572
// If we get to a ForeachStatement, check the keys and values
573573
if ($n instanceof Node\Statement\ForeachStatement) {
574-
if ($n->foreachKey && $n->foreachKey->expression->getName() === $name) {
574+
if ($n->foreachKey instanceof Node\Expression\Variable
575+
&& $n->foreachKey->expression->getName() === $name
576+
) {
575577
return $n->foreachKey;
576578
}
577579
if ($n->foreachValue

0 commit comments

Comments
 (0)