fix(php): 修复函数参数引用类型检查逻辑

- 移除对非引用类型变量的错误检查逻辑
- 简化参数引用转换流程
- 添加PHP 8.0类型声明兼容性测试用例
- 修复当参数为未定义变量时的引用创建机制
pull/1/head
韩天峰 4 months ago
parent eaa598a48e
commit 78b93ed32c
  1. 2
      src/Php/CompilerBase.php
  2. 18
      tests/aot/type_decl/008.phpt

@ -3315,8 +3315,6 @@ class CompilerBase extends \PhpAot\Core\Translator
// 若参数是引用类型,可以传入未定义变量,将立即创建变量作为引用
if (!$this->hasLocalVar($var)) {
$this->addLocalVar($var, self::TYPE_VAR);
} elseif ($this->getVarType($var) != self::TYPE_REF) {
$this->fatalError($arg, "Argument `{$argInfo->name}` must be a reference, `{$type}` given");
}
}
return $this->convertToRef($arg->value);

@ -0,0 +1,18 @@
--TEST--
Type Declarations
--FILE--
<?php
class Foo12 {
public function foo(): string {
$arr = [1, 2, 3, 4, 5];
return count($arr);
}
}
function main() {
$o = new Foo12;
var_dump($o->foo());
}
?>
--EXPECT--
string(1) "5"
Loading…
Cancel
Save