Incorrect `ReflectionClass::getNamespaceName` for anonymous class
Đang mở
Bug
Category: Engine
Extension: reflection
OS: Windows
Status: Verified
- 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
The following code:
<?php
namespace Foo {
interface InterfaceFoo {}
}
namespace Bar {
new class implements \Foo\InterfaceFoo {};
}
namespace {
foreach (get_declared_classes() as $class) {
if (!str_contains($class, '@anonymous')) {
continue;
}
echo 'Class: ', $class, PHP_EOL;
echo 'Namespace: ', (new ReflectionClass($class))->getNamespaceName(), PHP_EOL;
}
}
Resulted in this output:
Class: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace\test.php:8$0
Namespace: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace
at Windows and
Class: Foo\InterfaceFoo@anonymous/home/runner/work/php-anonymous-class-namespace/php-anonymous-class-namespace/test.php:8$0
Namespace: Foo
at Ubuntu
But I expected this output instead:
Class: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace\test.php:8$0
Namespace: Bar
Reproduced at https://github.com/werlos/php-anonymous-class-namespace (see the only action there).
PHP Version
8.3.0
Operating System
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với trình tái hiện PHP được cung cấp và entry point ReflectionClass::getNamespaceName(). So sánh đầu ra của nó trên Windows và Ubuntu với namespace mong đợi, sau đó kiểm tra pull request #12907 được liên kết trước khi thực hiện thay đổi. Hoàn tất khi lớp ẩn danh luôn báo cáo Bar một cách nhất quán.
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
- backend
- 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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 30/100