1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Stop undeclared variable warning for $obj->{$prop} syntax

Summary:
This isn't necessarily a root-cause solution but this syntax is really really
bad. If we want to fix the root cause, I'd recommend making its use a lint
error?

Test Plan:
Unit tests failed before patch, passed afterward.

Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran
Differential Revision: 270
This commit is contained in:
epriestley 2011-05-11 18:51:25 -07:00
parent 23afdb99f0
commit 3edd525f83
2 changed files with 13 additions and 3 deletions

View file

@ -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) {

View file

@ -156,6 +156,9 @@ class A {
}
}
function arrow($o, $x) {
echo $o->{$x->{$x->{$x.$x->{$x}}.$x}};
}
~~~~~~~~~~
error:30:3