From 057e25a950425a217136d621be94a4a08a9396b1 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 1 Jun 2026 19:46:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(type):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20str?= =?UTF-8?q?eam=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在类型解析中添加 stream 伪类型的识别和处理 - 将 stream 类型视为与 resource 相同的混合类型处理 - 更新类型映射表以支持 stream 类型到 ZEND_STR_MIXED 的转换 - 修改条件判断逻辑以包含 stream 类型的处理分支 --- src/gen_stub.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gen_stub.php b/src/gen_stub.php index 9e8928d1..c4cf6529 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -230,6 +230,13 @@ class SimpleType { return new SimpleType(ClassInfo::$currentClass, false); } + $name = $node->toLowerString(); + + // stream/box are compiler pseudo-types, treated like resource (mixed in arginfo) + if ($name === 'stream' || $name === 'box') { + return new SimpleType($name, true); + } + $class = $node->isFullyQualified() ? $node->toString() : getTranslator()->getNamespacedClassName($node->toString()); return new SimpleType($class, false); } @@ -271,7 +278,8 @@ class SimpleType { case "any": return new SimpleType('any', true); case "box": - return new SimpleType('box', true); + case "stream": + return new SimpleType($typeString, true); case "array": return ArrayType::createGenericArray(); case "self": @@ -393,6 +401,7 @@ class SimpleType { case "mixed": case "any": case "box": + case "stream": return ["IS_MIXED", "MAY_BE_ANY"]; case "void": return ["IS_VOID", "MAY_BE_VOID"]; @@ -455,6 +464,7 @@ class SimpleType { case "mixed": case "any": case "box": + case "stream": return "MAY_BE_ARRAY_OF_ANY"; case "ref": return "MAY_BE_ARRAY_OF_REF"; @@ -478,6 +488,7 @@ class SimpleType { case "mixed": case "any": case "box": + case "stream": return "MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY"; } @@ -2771,7 +2782,7 @@ class ConstInfo extends VariableLike { $type = $this->phpDocType ?? $this->type; $simpleType = $type ? $type->tryToSimpleType() : null; - if ($simpleType && ($simpleType->name === "mixed" || $simpleType->name === "any" || $simpleType->name === "box")) { + if ($simpleType && ($simpleType->name === "mixed" || $simpleType->name === "any" || $simpleType->name === "box" || $simpleType->name === "stream")) { $simpleType = null; } @@ -3047,6 +3058,7 @@ class StringBuilder { "mixed" => "ZEND_STR_MIXED", "any" => "ZEND_STR_MIXED", "box" => "ZEND_STR_MIXED", + "stream" => "ZEND_STR_MIXED", ]; // NEW in 8.1