1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 05:41:23 +01:00

Fix PHP5 static call fixup

Variable nodes directly store the variable name as a string, they
don't use VarLikeIdentifier. So remove this wrapper if it exists.
This commit is contained in:
Nikita Popov 2017-11-11 12:23:14 +01:00
parent a659240dc2
commit 4392a7b164
2 changed files with 11 additions and 13 deletions

View File

@ -19,6 +19,7 @@ use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\UseUse;
use PhpParser\Node\VarLikeIdentifier;
abstract class ParserAbstract implements Parser
{
@ -596,7 +597,9 @@ abstract class ParserAbstract implements Parser
*/
protected function fixupPhp5StaticPropCall($prop, array $args, array $attributes) : Expr\StaticCall {
if ($prop instanceof Node\Expr\StaticPropertyFetch) {
$var = new Expr\Variable($prop->name, $prop->name->getAttributes());
$name = $prop->name instanceof VarLikeIdentifier
? $prop->name->toString() : $prop->name;
$var = new Expr\Variable($name, $prop->name->getAttributes());
return new Expr\StaticCall($prop->class, $var, $args, $attributes);
} elseif ($prop instanceof Node\Expr\ArrayDimFetch) {
$tmp = $prop;
@ -615,9 +618,10 @@ abstract class ParserAbstract implements Parser
$this->fixupStartAttributes($tmp, $staticProp->name);
}
$result = new Expr\StaticCall($staticProp->class, $prop, $args, $attributes);
$tmp->var = new Expr\Variable($staticProp->name, $staticProp->name->getAttributes());
return $result;
$name = $staticProp->name instanceof VarLikeIdentifier
? $staticProp->name->toString() : $staticProp->name;
$tmp->var = new Expr\Variable($name, $staticProp->name->getAttributes());
return new Expr\StaticCall($staticProp->class, $prop, $args, $attributes);
} else {
throw new \Exception;
}

View File

@ -65,9 +65,7 @@ array(
)
)
name: Expr_Variable(
name: VarLikeIdentifier(
name: b
)
name: b
)
args: array(
)
@ -82,9 +80,7 @@ array(
)
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: VarLikeIdentifier(
name: b
)
name: b
)
dim: Scalar_String(
value: c
@ -104,9 +100,7 @@ array(
name: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: VarLikeIdentifier(
name: b
)
name: b
)
dim: Scalar_String(
value: c