fix(aot): 修复空合并赋值运算符测试用例和类名解析问题

- 更新测试用例 004.phpt 中的变量初始化顺序以匹配预期行为
- 修改 CompilerBase.php 中的类名解析逻辑,使用 getFullClassName() 替代直接访问 $this->class
- 确保 self 引用时获取完整的类名信息
pull/1/head
韩天峰 5 months ago
parent 52a0205c96
commit b0a6898ca8
  1. 2
      src/Php/CompilerBase.php
  2. 9
      tests/aot/coalesce/004.phpt

@ -4014,7 +4014,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$class = $this->parseIdentifier($expr->class); $class = $this->parseIdentifier($expr->class);
$propertyName = $this->parseIdentifier($expr->name); $propertyName = $this->parseIdentifier($expr->name);
if ($class === 'self') { if ($class === 'self') {
$class = $this->class; $class = $this->getFullClassName();
} elseif ($class === 'parent') { } elseif ($class === 'parent') {
if (!$this->classDef->extends) { if (!$this->classDef->extends) {
$this->fatalError($expr, 'Cannot access parent:: when current class does not extend any class'); $this->fatalError($expr, 'Cannot access parent:: when current class does not extend any class');

@ -3,16 +3,19 @@ Test ?? operator
--FILE-- --FILE--
<?php <?php
function foo1() { function foo1() {
$a = null;
$b = null;
$c = 100; $c = 100;
$a ??= $b ??= $c; $a ??= $b ??= $c;
var_dump($a, $b); var_dump($a, $b);
} }
function foo2() { function foo2() {
$c = 100; $a = null;
$b = 33; $b = 33;
$a ??= $b ??= $c; $c = 100;
$a ??= $b ??= $c;
var_dump($a, $b); var_dump($a, $b);
} }

Loading…
Cancel
Save