Skip to content

Commit

Permalink
Variable can be assigned inside an array dim fetch inside an isset
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 12, 2016
1 parent 6f9ff1e commit 075b492
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ private function lookForAssigns(Scope $scope, \PhpParser\Node $node): Scope
$scope = $this->lookForAssigns($scope, $node->expr);
} elseif ($node instanceof Foreach_) {
$scope = $this->lookForAssigns($scope, $node->expr);
} elseif ($node instanceof Isset_) {
foreach ($node->vars as $var) {
$scope = $this->lookForAssigns($scope, $var);
}
} elseif ($node instanceof ArrayDimFetch && $node->dim !== null) {
$scope = $this->lookForAssigns($scope, $node->dim);
}

$scope = $this->updateScopeForVariableAssign($scope, $node);
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Variables/data/defined-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,10 @@ function () use (&$errorHandler) {

}
echo $variableAssignedInForeach;

$someArray[$variableDefinedInDimFetch = 1];

if (isset($_[$variableAssignedInIsset = 123]) && $variableAssignedInIsset > 0) {
doFoo($variableAssignedInIsset); // defined here
}
doFoo($variableAssignedInIsset);

0 comments on commit 075b492

Please sign in to comment.