Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`object|<Class>` docblocks in `DispatchTrait` break metadata warmup under symfony/type-info 7.4 (`Cannot create union with both "object" and class type`)

已关闭 适合新手
#8,312 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
php, symfony
领域
api, backend

调研方向

先检查 src/Symfony/Messenger/DispatchTrait.php 和 src/Doctrine/Common/Messenger/DispatchTrait.php,然后使用报告中的 grep 命令确认两个冗余的 docblock。使用 Symfony TypeInfo 7.4 运行独立复现;完成的标准是元数据提取不再引发报告的联合类型异常。

由索引模型根据 Issue 内容生成。

描述

API Platform version

4.3.13

PHP version

8.4

Description

api-platform/core 4.3 ships redundant union docblocks of the form
object|<Class> in its own source:

  • src/Symfony/Messenger/DispatchTrait.php:28 → @param object|Envelope $message
  • src/Doctrine/Common/Messenger/DispatchTrait.php:28 → @param object|Envelope $message

With symfony/type-info 7.4 installed, the PhpStanExtractor that API Platform
wires as api_platform.property_info.php_stan_extractor throws an Exception while building
the type graph whenever it parses such a docblock:

Symfony\Component\TypeInfo\Exception\InvalidArgumentException:
Cannot create union with both "object" and class type.
  at vendor/symfony/type-info/Type/UnionType.php:75

object|Envelope is redundant — object already subsumes every class type.
The legacy symfony/property-info Type model tolerated this; symfony/type-info
7.4 rejects it hard.

This regressed cache:clear / routing warmup on the Symfony 7.3 → 7.4 bump.

Relation to #8201 / #8206

PR #8206 (released in 4.3.10) isolated the framework property_info service
from API Platform's extractors via private api_platform.property_info.* tags +
a bridge compiler pass. That fixed the path where API Platform's PhpStanExtractor
leaked into the framework service (Sylius @template T of object crash).

It does not cover this case: API Platform's own PhpStanExtractor still
parses object|<Class> docblocks during metadata warmup and hits the same
type-info exception. The remaining 4.3 path is still affected.

How to reproduce

Minimal standalone reproduction (public packages only, no app kernel needed):
https://gist.github.com/schmunk42/3357f3d0fdffe11e977812900355cefd

composer install
php repro.php
PHP            : 8.4.22
api-platform/core: v4.3.13
symfony/type-info: v7.4.9
symfony/property-info: v7.4.8
------------------------------------------------------------
[KO]  Symfony\Component\TypeInfo\Exception\InvalidArgumentException: Cannot create union with both "object" and class type.
      thrown from: .../symfony/type-info/Type/UnionType.php:75

The gist invokes the exact extractor API Platform wires as
api_platform.property_info.php_stan_extractor directly
Title:


on a property whose
docblock mirrors the DispatchTrait shape (@var object|Envelope).

You can also confirm the offending docblocks directly:

grep -rn "object|Envelope" vendor/api-platform/core/src
# src/Doctrine/Common/Messenger/DispatchTrait.php:28
# src/Symfony/Messenger/DispatchTrait.php:28

Possible solution

Drop the redundant |Envelope from both DispatchTrait docblocks — the
method already declares object $message / : Envelope in the signature, so
the docblock carries no extra information:

-    /**
-     * @param object|Envelope $message
-     */
     private function dispatch(object $message): Envelope

(or @param object $message if a docblock is desired). This keeps the source
free of redundant unions that symfony/type-info 7.4 rejects.

主要语言
PHP
星标
2.6k
派生
982
平均合并
1 天 17 小时
30 天内合并 PR
67

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

api-platform/core 的其他 Issue

查看 api-platform/core 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。