php / php/php-src

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

Đang mở
#20,112 2 bình luận 5 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Category: Engine Status: Verified
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với repository tái hiện và entry point class_exists(Entrypoint::class), sau đó so sánh autoload trace trên PHP 8.1.0 và các phiên bản mới hơn. Điều tra chuỗi kế thừa và kiểm tra LSP được thể hiện trong issue. Được coi là hoàn tất khi bản tái hiện hoàn thành mà không có fatal error và tạo ra thứ tự autoload như mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.