diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php index d6aafab7..38e21513 100644 --- a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php @@ -405,7 +405,7 @@ class ArcanistXHPASTLinter extends ArcanistLinter { // ($declarations). foreach ($vars as $var) { - $concrete = $var->getConcreteString(); + $concrete = $this->getConcreteVariableString($var); $declarations[$concrete] = min( idx($declarations, $concrete, PHP_INT_MAX), $var->getOffset()); @@ -445,7 +445,7 @@ class ArcanistXHPASTLinter extends ArcanistLinter { // figure out. continue; } - $concrete = $var->getConcreteString(); + $concrete = $this->getConcreteVariableString($var); if ($var->getOffset() >= idx($declarations, $concrete, PHP_INT_MAX)) { // The use appears after the variable is declared, so it's fine. continue; @@ -466,6 +466,13 @@ class ArcanistXHPASTLinter extends ArcanistLinter { } } + private function getConcreteVariableString($var) { + $concrete = $var->getConcreteString(); + // Strip off curly braces as in $obj->{$property}. + $concrete = trim($concrete, '{}'); + return $concrete; + } + protected function lintPHPTagUse($root) { $tokens = $root->getTokens(); foreach ($tokens as $token) { diff --git a/src/lint/linter/xhpast/__tests__/data/undeclared-variables.lint-test b/src/lint/linter/xhpast/__tests__/data/undeclared-variables.lint-test index 4e2f723e..0add1437 100644 --- a/src/lint/linter/xhpast/__tests__/data/undeclared-variables.lint-test +++ b/src/lint/linter/xhpast/__tests__/data/undeclared-variables.lint-test @@ -155,7 +155,10 @@ class A { return 2; } } - + +function arrow($o, $x) { + echo $o->{$x->{$x->{$x.$x->{$x}}.$x}}; +} ~~~~~~~~~~ error:30:3