php / php/php-src

Hard to figure out from an error message where incompatible method declarations meet

Đang mở
#12,091 6 bình luận 14 reaction 1 người được giao Xem trên GitHub

@derickr đang làm issue này rồi.

Từ ngày 31/8/2023.

Feature Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

When we launch a PHP application, we might get a similar message:

Fatal error: Declaration of Baz::getId(): mixed must be compatible with Foo::getId(): int in /tmp/preview on line 13

When we look up the declarations of these methods, we get this:

interface Foo
{
    
    public function getId(): int;
    
}

abstract class Baz
{
    
    public function getId(): mixed
    {
        //...
    }
    
}

They have nothing in common, their existence on their own shouldn't be a problem for our application.

The problem is when they meet via a common child that both extends Baz and implements Foo:

class Lorem extends Baz implements Foo
{
    
}

The problem is that we don't learn about Lorem from the PHP error message which makes it really hard to find Loremin a large application.

Personally I solved it by enabling Xdebug in develop mode and looking at the stack trace. One (or both) of these two things would help to debug this problem in the future:

  1. Show fatal error stack trace in PHP out of the box, without requiring Xdebug.
  2. Somehow include Lorem too in this error message: Fatal error: Declaration of Baz::getId(): mixed must be compatible with Foo::getId(): int in /tmp/preview on line 13

3v4l.org link: https://3v4l.org/4iOYG

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.

Đánh giá

Issue này chưa được đánh giá.

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.