From 4392a7b16418630ed8c2817bf18d6096e3e462df Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 11 Nov 2017 12:23:14 +0100 Subject: [PATCH] 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. --- lib/PhpParser/ParserAbstract.php | 12 ++++++++---- test/code/parser/expr/fetchAndCall/staticCall.test | 12 +++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index a55052f..70cc07e 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -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; } diff --git a/test/code/parser/expr/fetchAndCall/staticCall.test b/test/code/parser/expr/fetchAndCall/staticCall.test index 4af7e7d..a34a3e4 100644 --- a/test/code/parser/expr/fetchAndCall/staticCall.test +++ b/test/code/parser/expr/fetchAndCall/staticCall.test @@ -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