fix(php): 修复编译器中的条件判断逻辑错误

- 修正了 isClassConstFetch 条件判断的位置,确保正确的执行流程
- 补全了 DynamicCall 异常捕获后的代码块结构
- 修复了静态方法调用检查中的条件表达式逻辑
- 统一了 Translator 中的 elseif 语法使用规范
pull/1/head
韩天峰 4 months ago
parent 1fbaa07820
commit 583536a24e
  1. 8
      src/Php/CompilerBase.php
  2. 2
      src/Php/Translator.php

@ -1500,7 +1500,8 @@ class CompilerBase extends \PhpAot\Core\Translator
$argClass = $expr->args[1]->value;
if ($this->isScalarString($argClass)) {
return $this->getNamespacedClassName($this->parseIdentifier($argClass));
} elseif ($this->isClassConstFetch($argClass)) {
}
if ($this->isClassConstFetch($argClass)) {
if ($this->isNameExpr($argClass->class) and $this->isIdExpr($argClass->name) and $this->parseIdentifier($argClass->name) === 'class') {
return $this->getNamespacedClassName($this->parseIdentifier($argClass->class));
}
@ -1516,7 +1517,8 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($nativeFunc) {
return $this->getFunction($nativeFunc)->returnClass;
}
} catch (DynamicCall) {}
} catch (DynamicCall) {
}
}
if ($this->isStaticCall($expr) and $this->isNameExpr($expr->class) and $this->isNamedMethod($expr->name)) {
$class = $this->parseIdentifier($expr->class);
@ -4045,7 +4047,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$fn = 'php::concat({' . $this->identifierToStr($expr->class) . ', "::", ' . $this->identifierToStr($expr->name) . '})';
}
$placeHolder = $fn;
} elseif ($class === 'static') {
} elseif ($this->isNameExpr($expr->class) and $class === 'static') {
$methodPtr = $this->identifierToStr($expr->name, literal: true);
$fn = Symbol::getCalledCe() . ', php::getMethod(' . Symbol::getCalledCe() . ', ' . $methodPtr . ')';
$this->context->beforeStmtLines[] = '// Static Method Call: static::' . $this->parseIdentifier($expr->name) . '()';

@ -591,7 +591,7 @@ class Translator extends Preprocessor
}
} elseif (is_float($value)) {
return $value;
} else if (is_bool($value)) {
} elseif (is_bool($value)) {
return $value ? 1 : 0;
} elseif (is_string($value)) {
return $this->genCharPtr($value);

Loading…
Cancel
Save