php / php/php-src

Reflection parameter type could be more precise about specific BackedEnum::from() and tryFrom() type

オープン
#12,865 コメント 15 件 リアクション 2 件 担当者 0 名 GitHub で見る

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

  • #18016 @DanielEScherzer による — マージされずにクローズ
Bug Extension: reflection Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php

declare(strict_types=1);

enum IntBacked: int {
    case One = 1;
}

$rm = new ReflectionMethod(IntBacked::class, 'tryFrom');
var_export((string) $rm->getParameters()[0]->getType());

Resulted in this output:

'string|int'

But I expected this output instead:

'int'

Because when a bad type is passed in there, it's rejected with TypeError:

Argument #1 ($value) must be of type int, string given

Related: https://github.com/php/php-src/issues/12863

PHP Version

PHP 8.1+

Operating System

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず、提供された PHP スニペットを実行し、特定のエントリーポイントである BackedEnum::tryFrom() について ReflectionMethod::getParameters() を追跡します。リフレクションが IntBacked::tryFrom() に対して int を報告する一方で、文字列を渡すと示されている TypeError が引き続き発生することを確認してください。issue ではソースファイルやテストのパスは指定されていません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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