fix(php): 修复作用域管理和类型转换问题

- 修正了 leaveScope 方法中的作用域级别递减顺序
- 将致命错误改为普通错误以处理浮点数到大整数的转换
- 使用严格相等比较修复数组变量检测逻辑
pull/1/head
韩天峰 3 months ago
parent b89dd177b3
commit 2bfd171a24
  1. 2
      src/Php/Context/FunctionContext.php
  2. 2
      src/Php/Parser/TypeConversionTrait.php
  3. 2
      src/Php/Parser/TypeDetectionTrait.php

@ -96,7 +96,7 @@ class FunctionContext
public function leaveScope(): void public function leaveScope(): void
{ {
unset($this->scopeLayouts[$this->scopeLevel]);
$this->scopeLevel--; $this->scopeLevel--;
unset($this->scopeLayouts[$this->scopeLevel]);
} }
} }

@ -76,7 +76,7 @@ trait TypeConversionTrait
return 'php::toBigInt(' . $this->trimBrackets($expr) . ')'; return 'php::toBigInt(' . $this->trimBrackets($expr) . ')';
} }
if ($fromType === self::TYPE_FLOAT) { if ($fromType === self::TYPE_FLOAT) {
$this->fatalError(null, 'Cannot convert float to BigInt, use string or int instead'); $this->error('Cannot convert float to BigInt, use string or int instead');
} }
if ($fromType === self::TYPE_STR) { if ($fromType === self::TYPE_STR) {
return 'php::toBigInt(php::toString(' . $this->trimBrackets($expr) . '))'; return 'php::toBigInt(php::toString(' . $this->trimBrackets($expr) . '))';

@ -138,7 +138,7 @@ trait TypeDetectionTrait
protected function isArrayVar($var): bool protected function isArrayVar($var): bool
{ {
return $this->isVarExpr($var) and $this->hasVar($var->name) and $this->getVarType($var->name) == self::TYPE_ARRAY; return $this->isVarExpr($var) and $this->hasVar($var->name) and $this->getVarType($var->name) === self::TYPE_ARRAY;
} }
} }

Loading…
Cancel
Save