From 183b2ba96cb61a8f89388f7649d028e9654c8b15 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 25 Mar 2026 13:50:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E6=9C=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 未定义类型时,属性和参数默认使用 var (mixed, any) 类型 - 未定义类型时,返回值默认使用 void 类型 - 根据声明类型上下文返回相应的默认类型值 --- src/Php/CompilerBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index b7a45402..adb0f6cf 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -749,9 +749,9 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseTypeDecl(?NodeAbstract $type, int $what): string { - // 未定义类型,默认是 var (mixed, any) + // 未定义类型,属性、参数默认是 var (mixed, any) ,返回值是 void if ($type === null) { - return self::TYPE_VAR; + return $what === self::DECL_TYPE_OF_RETURN ? self::TYPE_VOID : self::TYPE_VAR; } if ($type instanceof UnionType or $type instanceof NullableType) { // 联合类型暂时不支持,使用 var 类型代替