From ec5f393a272bea236460a9f69105a87703bf1a52 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 28 May 2026 19:22:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E5=B0=86=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E7=B1=BB=E5=B8=B8=E9=87=8F=E6=9B=B4=E6=96=B0=E5=86=99=E5=85=A5?= =?UTF-8?q?=E5=88=B0=20ZendVM=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/Translator.php | 7 +++++++ tests/aot/trait/010.phpt | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/aot/trait/010.phpt diff --git a/src/Php/Translator.php b/src/Php/Translator.php index d89eeb53..96484f7a 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -604,6 +604,10 @@ CODE; if ($constant->type === self::TYPE_ARRAY) { $constName = self::PREFIX . $this->getNativeName($constant->name, $classDef->namespace, $classDef->name); $code .= $constName . ".unset();\n"; + + $classNameStr = $this->genCharPtr($classDef->getNamespacedName(false), true); + $classConstStr = $this->genCharPtr($constant->name); + $code .= "php::updateConstant($classNameStr, $classConstStr, php::null);\n"; } } } @@ -1278,6 +1282,9 @@ CODE; $code .= "do {\n"; $code .= $constant->arrayExpr; $code .= $constName . ' = ' . $constant->value . ";\n"; + $classNameStr = $this->genCharPtr($classDef->getNamespacedName(false), true); + $classConstStr = $this->genCharPtr($constant->name); + $code .= "php::updateConstant($classNameStr, $classConstStr, {$constant->value});\n"; $code .= "} while(0);\n"; } } diff --git a/tests/aot/trait/010.phpt b/tests/aot/trait/010.phpt new file mode 100644 index 00000000..23e04754 --- /dev/null +++ b/tests/aot/trait/010.phpt @@ -0,0 +1,41 @@ +--TEST-- +trait full class name +--FILE-- + 'Hello 1', + ]; + public function hello() + { + var_dump(self::DATA); + var_dump(self::DATA[\App3\TraitsTest::NAME]); + } + } +} + +namespace App3 { + use App2\THello1; + class TraitsTest + { + public const NAME = 'test_trait'; + use THello1; + } +} + +namespace { + function main() + { + $o = new App3\TraitsTest; + $o->hello(); + } +} +?> +--EXPECT-- +array(1) { + ["test_trait"]=> + string(7) "Hello 1" +} +string(7) "Hello 1" \ No newline at end of file