php / php/php-src

Override construct function with optional argument should not produce fatal error

オープン
#23,630 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

Bug Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php
    interface MyInterface1 { public function __construct(?string $name = null); }
    interface MyInterface2 { public function __construct(?string $name = null, ?int $id = null); }

    interface MyInterface3 extends MyInterface1, MyInterface2 { }

Resulted in this output:

PHP Fatal error:  Declaration of MyInterface1::__construct(?string $name = null) must be compatible with MyInterface2::__construct(?string $name = null, ?int $id = null) in php shell code on line 1

But I expected no error and the following code works as expected:

<?php
    interface MyInterface1 { public function __construct(?string $name = null); }
    interface MyInterface2 { public function __construct(?string $name = null, ?int $id = null); }

    interface MyInterface4 extends MyInterface2, MyInterface1 { }
PHP Version
PHP 8.4.24 (cli) (built: Jul 30 2026 15:23:13) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.24, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.24, Copyright (c), by Zend Technologies
Operating System

Ubuntu 24.04.4 LTS

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

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

はじめの一歩

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

調査の方向性

PHP 8.4.24で2つのインターフェース継承スニペットを再現し、親インターフェースの順序と、それによって発生するコンストラクター互換性エラーを比較します。まず、継承されたインターフェースメソッドを検証するengineの経路を追跡します。報告されたfatal errorなしに両方の宣言順序が一貫して動作し、そのケースをカバーする回帰テストが追加されれば完了です。

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

評価

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

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

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