Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの 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 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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 でスタンドアロンの再現を実行します。メタデータの抽出で報告された union 型の例外が発生しなくなれば完了です。

索引モデルが 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時間
マージ済み PR(30日)
67

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。