From 4f375bf869e75f9009b279171ac8851149ff134e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 4 Mar 2026 12:26:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E7=AC=A6=E8=BD=AC=E6=8D=A2=E6=96=B9=E6=B3=95=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AD=97=E9=9D=A2=E9=87=8F=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 identifierToStr 方法中添加 literal 参数以控制字符串生成方式 - 修改 MethodCall 处理逻辑以使用字面量模式进行标识符转换 - 实现字面量模式下的字符串处理逻辑,根据参数决定返回字面量还是指针 - 更新方法签名以兼容新的字面量参数选项 --- src/Php/CompilerBase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6bf4aaf0..6f71d06b 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3345,7 +3345,7 @@ class CompilerBase extends \PhpAot\Core\Translator $class = ''; } - $method = $this->identifierToStr($expr->name); + $method = $this->identifierToStr($expr->name, literal: true); // 可转为原生调用的 MethodCall if ($this->isVarExpr($expr->var) and $this->isNamedMethod($expr->name)) { @@ -3378,7 +3378,7 @@ class CompilerBase extends \PhpAot\Core\Translator } } - protected function identifierToStr(NodeAbstract $node, bool $require = true): string + protected function identifierToStr(NodeAbstract $node, bool $require = true, bool $literal = false): string { $id = $this->parseIdentifier($node); if ($this->isVarExpr($node)) { @@ -3395,7 +3395,7 @@ class CompilerBase extends \PhpAot\Core\Translator $id = $this->getNamespacedClassName($this->class); } if ($this->isNameExpr($node) or $this->isIdExpr($node)) { - return $this->genCharPtr($id, true); + return $literal ? $this->getLiteralString($id) : $this->genCharPtr($id, true); } return $id; }