From 67932cd29685cce67395ad166a30502610d6de50 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Apr 2020 18:23:52 +1200 Subject: [PATCH] stmt/class: support static calls --- fixtures/0005-inheritance.php | 14 ++++++++++++++ node.go | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/fixtures/0005-inheritance.php b/fixtures/0005-inheritance.php index af0404d..48d59d9 100644 --- a/fixtures/0005-inheritance.php +++ b/fixtures/0005-inheritance.php @@ -7,6 +7,10 @@ class Base { $this->mX = $x; } + public function Val() { + return 3; + } + static function TheStatic() {} } @@ -19,4 +23,14 @@ class Child extends Base { $this->mY = 0; } + public function Val() { + return 4; + } + + public function Combine() { + return $this->Val() + parent::Val(); + } + } + +echo (new Child(0))->Combine(); diff --git a/node.go b/node.go index 5a8fc65..ee8ca85 100644 --- a/node.go +++ b/node.go @@ -459,6 +459,24 @@ func convert(n_ node.Node) (string, error) { return funcName + callParams, nil // expr only, no semicolon/newline + case *expr.StaticCall: + className, err := resolveName(n.Class) + if err != nil { + return "", parseErr{n, err} + } + + funcName, err := convert(n.Call) + if err != nil { + return "", parseErr{n, err} + } + + callParams, err := convertFuncCallArgsCommon(n.ArgumentList) + if err != nil { + return "", parseErr{n, err} + } + + return className + "." + funcName + callParams, nil // expr only, no semicolon/newline + case *expr.New: // new foo(xx) // Transparently convert to calling constructor function.