diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 3cf3ff7d..54f6dcd2 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -844,11 +844,10 @@ class CompilerBase extends \PhpAot\Core\Translator $type = self::TYPE_OBJECT; } elseif ($this->isFuncCallExpr($right) and $this->isNameExpr($right->name)) { $fn = $this->parseIdentifier($right->name); - $arg2 = $right->args[1]->value; - if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($arg2)) { - $this->objects[$var] = $arg2->value; + if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) { + $this->objects[$var] = $right->args[1]->value; + $type = self::TYPE_OBJECT; } - $type = self::TYPE_OBJECT; } if (!$this->hasVar($var)) { diff --git a/src/Php/FunctionDef.php b/src/Php/FunctionDef.php index 91403f17..bf737207 100644 --- a/src/Php/FunctionDef.php +++ b/src/Php/FunctionDef.php @@ -9,6 +9,7 @@ class FunctionDef public array $argInfoList = []; public int $argCountRequired = 0; public string $params = ''; + public bool $method = false; public function __construct(string $name, string $returnType) diff --git a/src/Php/MethodDef.php b/src/Php/MethodDef.php index 900c7826..11c1d15c 100644 --- a/src/Php/MethodDef.php +++ b/src/Php/MethodDef.php @@ -13,6 +13,7 @@ class MethodDef $this->flags = $flags; $this->name = $name; $this->functionDef = $def; + $this->functionDef->method = true; } public function getReturnType(): string diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d54089e9..24f3d3c2 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -426,6 +426,9 @@ class Translator extends Preprocessor $argInfoList = $func->argInfoList; if ($argInfoList) { $list = []; + if ($func->method) { + $list[] = 'php::Object &this_'; + } foreach ($argInfoList as $argInfo) { $arg = $argInfo->type . ' ' . $argInfo->name; if ($argInfo->default) {