php / php/php-src

Fatal error during autoloading of complex inheritance chain with LSP checks since PHP 8.1.0

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

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

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

説明

Description

The following code:

<?php

$depth = 0;

spl_autoload_register(function ($class) use (&$depth) {
    $depth++;
    $indent = str_repeat('| ', $depth);
    echo $indent."$depth: $class\n";

    if ($class == 'IFace') {
        interface IFace {}
    } elseif ($class == 'IFaceImplementor') {
        class IFaceImplementor implements IFace {}
    } elseif ($class == 'InterfaceOfMainParent') {
        interface InterfaceOfMainParent
        {
            public function methodForSecondaryLspCheck(): IFace;
        }
    } elseif ($class == 'MainParent') {
        abstract class MainParent implements InterfaceOfMainParent
        {
            public function methodForSecondaryLspCheck(): IFaceImplementor {}
        }
    } elseif ($class == 'Intermediate') {
        abstract class Intermediate extends MainParent {}
    } elseif ($class == 'Child1') {
        class Child1 extends Intermediate {}
    } elseif ($class == 'Child2') {
        class Child2 extends Intermediate {}
    } elseif ($class == 'EntrypointParent') {
        abstract class EntrypointParent
        {
            abstract public function methodForLspCheck1(): MainParent;
            abstract public function methodForLspCheck2(): MainParent;
        }
    } elseif ($class == 'Entrypoint') {
        class Entrypoint extends EntrypointParent
        {
            public function methodForLspCheck1(): Child1 {}
            public function methodForLspCheck2(): Child2 {}
        }
    }

    $depth--;
});

class_exists(Entrypoint::class);

Resulted in this output:

| 1: Entrypoint
| | 2: EntrypointParent
| | 2: Child1
| | | 3: Intermediate
| | | | 4: MainParent
| | | | | 5: InterfaceOfMainParent
| | | | | 5: Child2

Fatal error: During inheritance of MainParent, while autoloading Child2: Uncaught Error: Class "Intermediate" not found in php-wasm run script:29
Stack trace:
#0 php-wasm run script(20): {closure}('Child2')
#1 php-wasm run script(25): {closure}('MainParent')
#2 php-wasm run script(27): {closure}('Intermediate')
#3 php-wasm run script(37): {closure}('Child1')
#4 [internal function]: {closure}('Entrypoint')
#5 php-wasm run script(47): class_exists('Entrypoint')
#6 {main} in php-wasm run script on line 20

But I expected this output instead:

| 1: Entrypoint
| | 2: EntrypointParent
| | 2: Child1
| | | 3: Intermediate
| | | | 4: MainParent
| | | | | 5: InterfaceOfMainParent
| | | | | 5: IFaceImplementor
| | | | | | 6: IFace
| | 2: Child2
PHP Version
PHP 8.5.0RC1 (cli) (built: Oct  8 2025 22:41:41) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.0RC1, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.0RC1, Copyright (c), by Zend Technologies
Operating System

No response

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

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

はじめの一歩

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

調査の方向性

再現用リポジトリとエントリーポイント class_exists(Entrypoint::class) から始め、その後、PHP 8.1.0 とそれ以降のバージョンで autoload trace を比較してください。issue に示されている継承および LSP-check のシーケンスを調査してください。再現が fatal error なしで完了し、期待される autoload の順序が生成されれば完了です。

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

評価

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

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

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