From af42804d8ff8e10361109b8a9c1f5e7282f5f7a0 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 3 Apr 2026 17:29:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=99=A8=E5=B8=B8=E9=87=8F=E5=92=8C=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 parseAssignFinally 方法添加参数类型声明 - 重命名 getClassConst 为 findNativeClassConst 方法 - 为表达式添加 nativeConst 属性标记原生常量 - 添加对静态属性获取的检查和处理逻辑 - 更新常量获取调用以使用新方法名 --- src/Php/CompilerBase.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 6313b5f3..be2a673f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1307,7 +1307,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseAssignFinally($left, $right); } - protected function parseAssignFinally($left, $right): string + protected function parseAssignFinally(Node\Expr $left, Node\Expr $right): string { if ($left instanceof Expr\List_) { $items = $left->items; @@ -1747,7 +1747,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->getNativeName($method, $classDef->namespace, $classDef->name); } - protected function getClassConst(NodeAbstract $expr, string $class, string $const): string|false + protected function findNativeClassConst(NodeAbstract $expr, string $class, string $const): string|false { if (!$this->hasClass($class)) { return false; @@ -1776,6 +1776,7 @@ class CompilerBase extends \PhpAot\Core\Translator if ($constDef->type === self::TYPE_ARRAY) { return self::PREFIX . $this->getNativeName($constDef->name, $classDef->namespace, $classDef->name); } else { + $expr->setAttribute('nativeConst', $constDef); return $constDef->value; } } @@ -3662,6 +3663,12 @@ class CompilerBase extends \PhpAot\Core\Translator 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')) { + return $fn . '(' . $prop . ')'; + } + } $list = []; while (true) { @@ -4109,7 +4116,7 @@ class CompilerBase extends \PhpAot\Core\Translator $ce = $this->getClassEntryPtr($class); return 'php::getEnumCase(' . $ce . ', ' . $this->getLiteralString($const) . ')'; } - $nativeConst = $this->getClassConst($expr, $class, $const); + $nativeConst = $this->findNativeClassConst($expr, $class, $const); if ($nativeConst) { return $nativeConst; }