fix(php): 将数组类常量更新写入到 ZendVM 中

pull/1/head
韩天峰 3 months ago
parent 95b1c89053
commit ec5f393a27
  1. 7
      src/Php/Translator.php
  2. 41
      tests/aot/trait/010.phpt

@ -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";
}
}

@ -0,0 +1,41 @@
--TEST--
trait full class name
--FILE--
<?php
namespace App2 {
trait THello1
{
public const array DATA = [
\App3\TraitsTest::NAME => '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"
Loading…
Cancel
Save