stmt/class: support static calls

This commit is contained in:
mappu 2020-04-05 18:23:52 +12:00
parent 6b40079884
commit 67932cd296
2 changed files with 32 additions and 0 deletions

View File

@ -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();

18
node.go
View File

@ -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.