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