From 58f9cb4c28620eb8116df4bbb613217351e12ead Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 23 Jan 2026 13:49:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8DPHP=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E7=B1=BB=E5=9E=8B=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将TYPE_REF常量值从'php::Var'更改为'php::Ref' - 修改引用参数传递逻辑,使用'&'操作符而不是解引用 - 将post-increment操作符错误处理从parsePostOp改为fatalError - 修复变量赋值时的引用处理逻辑 - 添加引用操作符测试用例 --- src/Php/CompilerBase.php | 11 +++++------ tests/aot/ref.phpt | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tests/aot/ref.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index df0f3539..312b60cf 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -33,7 +33,7 @@ class CompilerBase extends \PhpAot\Core\Translator public const string TYPE_OBJECT = 'php::Object'; public const string TYPE_ARRAY = 'php::Array'; public const string TYPE_STR = 'php::Str'; - public const string TYPE_REF = 'php::Var'; + public const string TYPE_REF = 'php::Ref'; public const string TYPE_VOID = 'void'; public const string VALUE_NAN = 'std::numeric_limits::quiet_NaN()'; @@ -1493,8 +1493,7 @@ class CompilerBase extends \PhpAot\Core\Translator $tmpVar = $this->genTmpVarName(); $this->addLocalVar($tmpVar, self::TYPE_REF); $this->beforeStmtLines[] = $tmpVar . ' = ' . $this->parseExpr($arg->value) . '.toReference();'; - $this->afterStmtLines[] = $name . ' = *' . $tmpVar . ';'; - $list_args[] = $tmpVar; + $list_args[] = '&' . $tmpVar; continue; } } elseif ($this->isPropertyFetch($arg->value)) { @@ -1539,7 +1538,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->afterStmtLines[] = 'php::setStaticProperty(' . $class . ', ' . $prop . ', ' . $tmpVar . ' ' . $op . ' 1);'; return $tmpVar; } - $this->parsePostOp($expr, "Post-increment operator is not supported for non-variable expressions"); + $this->fatalError($expr, "Post-increment operator is not supported for non-variable expressions"); } protected function parsePostDec($expr): string @@ -2394,10 +2393,10 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isVarExpr($expr->var)) { $var = $this->parseIdentifier($expr->var); if (!$this->hasVar($var)) { - $this->addLocalVar($var, self::TYPE_VAR); + $this->addLocalVar($var, self::TYPE_REF); } if ($this->isVarExpr($expr->expr)) { - return $var . ' = &' . $this->parseIdentifier($expr->expr); + return $var . ' = ' . $this->parseIdentifier($expr->expr) . '.toReference()'; } elseif ($expr->expr->getType() === self::EXPR_ARRAY_DIM_FETCH) { return $var . ' = ' . $this->parseIdentifier($expr->expr); } elseif ($this->isPropertyFetch($expr->expr)) { diff --git a/tests/aot/ref.phpt b/tests/aot/ref.phpt new file mode 100644 index 00000000..5b6714cd --- /dev/null +++ b/tests/aot/ref.phpt @@ -0,0 +1,19 @@ +--TEST-- +object link operator +--FILE-- + +--EXPECT--