feat(php): 添加对联合类型的支持

- 在编译器基类中处理UnionType情况,将其转换为mixed类型
- 添加nullable类型属性的测试用例
- 实现对union类型参数的正确解析和处理逻辑
pull/1/head
韩天峰 5 months ago
parent 537222b1e7
commit f3fd30c662
  1. 3
      src/Php/CompilerBase.php
  2. 18
      tests/aot/prop-004.phpt

@ -1004,6 +1004,9 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($param->type instanceof NullableType) {
$type = $param->type->type;
$nullable = true;
} elseif ($param->type instanceof UnionType) {
$type = 'mixed';
$nullable = false;
} else {
$type = $param->type === null ? '' : $param->type;
$nullable = false;

@ -0,0 +1,18 @@
--TEST--
Property with nullable type
--FILE--
<?php
class Foo
{
public function __construct(public string|Stringable $value)
{
}
}
function main() {
$foo = new Foo('Continue');
var_dump($foo->value);
}
?>
--EXPECT--
string(8) "Continue"
Loading…
Cancel
Save