From 28f2b5ac8aacbdaee100da93294e6528b880ce0b Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 24 Mar 2026 19:09:32 +0800 Subject: [PATCH] =?UTF-8?q?test(class-const):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B1=BB=E5=B8=B8=E9=87=8F=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=B8=B8=E9=87=8F=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 class-const-003.phpt 测试文件验证类常量功能 - 修复数组类型类常量的值复制逻辑 - 移除未使用的 Zend 引擎常量表更新代码 - 统一代码风格将冒号语法替换为大括号语法 - 简化类常量更新方法的控制流程 --- src/Php/Translator.php | 19 ++++++------------- tests/aot/class-const-003.phpt | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 tests/aot/class-const-003.phpt diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 1ad3b58f..4ce4a7f5 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -526,21 +526,14 @@ class Translator extends Preprocessor protected function genUpdateClassConstants(): string { $code = ''; - foreach ($this->classes as $classDef) : - foreach ($classDef->constants as $constant) : - if ($constant->type === self::TYPE_ARRAY) : + foreach ($this->classes as $classDef) { + foreach ($classDef->constants as $constant) { + if ($constant->type === self::TYPE_ARRAY) { $constName = self::PREFIX . $this->getNativeName($constant->name, $classDef->namespace, $classDef->name); $code .= $constName . " = " . $constant->value . ";\n"; - if (false) { - $code .= "do {\n"; - $code .= "auto c = (zend_class_constant *) zend_hash_str_find_ptr(&" . $this->getClassCe($classDef) . "->constants_table, ZEND_STRL(\"" . $constant->name . "\"));"; - $code .= "c->type = (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY);\n"; - $code .= "ZVAL_COPY(&c->value, $constName.ptr());\n"; - $code .= " } while (0); \n"; - } - endif; - endforeach; - endforeach; + } + } + } return $code; } diff --git a/tests/aot/class-const-003.phpt b/tests/aot/class-const-003.phpt new file mode 100644 index 00000000..d724eea4 --- /dev/null +++ b/tests/aot/class-const-003.phpt @@ -0,0 +1,31 @@ +--TEST-- +class const 002 +--FILE-- + self::V1, + 'b' => self::V2, + ]; +} + +function main() +{ + var_dump(Worker::V1); + var_dump(Worker::V2); + var_dump(Worker::ARR); +} +?> +--EXPECT-- +int(1999) +int(1999) +array(2) { + ["a"]=> + int(1999) + ["b"]=> + int(1999) +}