From 15bcacacc08998b810c55ad158f9d0548e15c9c3 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 26 Jun 2026 18:40:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E9=9D=99=E6=80=81=E5=B1=9E=E6=80=A7=E5=A4=84=E7=90=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在引用参数解析中添加临时变量处理以支持引用类型参数 - 为静态属性获取器添加 toReference() 方法调用支持 - 添加新的测试用例验证静态属性引用操作的正确性 - 优化编译器对 nativeProperty 属性的引用值处理逻辑 --- src/Php/CompilerBase.php | 11 +++++++- tests/aot/ref/ref-static-prop.phpt | 41 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/aot/ref/ref-static-prop.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ff9e57d3..87c607f9 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3055,7 +3055,10 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isScalar($arg->value)) { $this->fatalError($arg, 'The constants cannot be used as an argument for a reference-type parameter'); } - $list_args[] = $this->parseChainedExpr($arg->value, self::OP_REFVAL); + $tmpRef = $this->genTmpVarName(); + $this->addLocalVar($tmpRef, self::TYPE_REF); + $this->context->beforeStmtLines[] = $tmpRef . ' = ' . $this->parseChainedExpr($arg->value, self::OP_REFVAL) . ';'; + $list_args[] = '&' . $tmpRef; continue; } } @@ -4478,12 +4481,18 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isPropertyFetch($expr) and $this->isVarExpr($expr->var) and $this->isIdExpr($expr->name)) { $prop = $this->parsePropertyFetch($expr); if ($expr->hasAttribute('nativeProperty')) { + if ($op === self::OP_REFVAL) { + return $prop . '.toReference()'; + } return $fn . '(' . $prop . ')'; } } if ($this->isStaticPropertyFetch($expr) and $this->isNameExpr($expr->class) and $this->isIdExpr($expr->name)) { $prop = $this->parseStaticPropertyFetch($expr); if ($expr->hasAttribute('nativeProperty')) { + if ($op === self::OP_REFVAL) { + return $prop . '.toReference()'; + } return $fn . '(' . $prop . ')'; } } diff --git a/tests/aot/ref/ref-static-prop.phpt b/tests/aot/ref/ref-static-prop.phpt new file mode 100644 index 00000000..98c64eb9 --- /dev/null +++ b/tests/aot/ref/ref-static-prop.phpt @@ -0,0 +1,41 @@ +--TEST-- +object link operator +--FILE-- + +--EXPECT-- +OK