refactor(php): 移除循环变量声明的特殊处理逻辑

- 删除了对 Expr_Assign 类型表达式的特殊处理
- 移除了循环变量声明的本地变量添加逻辑
- 简化了条件表达式解析流程
- 统一了表达式处理方式,不再区分赋值表达式类型
pull/1/head
韩天峰 7 months ago
parent 209b9cb81d
commit 668f440254
  1. 10
      src/Php/CompilerBase.php

@ -1544,16 +1544,6 @@ class CompilerBase extends \PhpAot\Core\Translator
$list_cond = [];
foreach ($cond as $expr) {
if ($expr->getType() === 'Expr_Assign') {
$left = $expr->var;
$name = $this->parseIdentifier($left);
$type = $this->detectExprType($expr->expr);
// for 循环的变量声明,必须在循环体之外,不能创建 scope tmp var
if (!$this->hasVar($name)) {
$this->addLocalVar($name, $type);
}
$code .= $name . ' = (' . $this->parseIdentifier($expr->expr) . ');';
}
$list_cond[] = $this->parseExpr($expr);
}

Loading…
Cancel
Save