php / php/php-src

Make evaled code/tokens accessible

Đang mở
#8,782 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Feature Status: Needs Triage
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

Code like:

<?php

namespace N;

class Cl {}

eval(<<<'EOF'
    use N\Cl;
    
    class U {
        /**
         * @return Cl
         */
        public function test() { throw new \Exception(); }
    }
EOF);

$u = new \U();
$refl = new \ReflectionMethod($u, 'test');
var_dump($refl->getFileName());
var_dump($refl->getDocComment());

has unusable phpdoc, as it relies on a use N\Cl; statement. The issue is phpdoc can be accessed by reflection - https://3v4l.org/djLIA - but the full evaled code is not accessible thus the use statements required to parse the phpdoc cannot be read.

At least I am unaware of any way to access the evaled code (or parsed tokens).

The ability to resolve phpdoc for classes from eval is important as annotations are used by many production libs (like Doctrine ORM) and also for static analysers.

This is a feature request to make the full evaled code accessible at least via new reflection ReflectionClass::getFileContents() method. If the parsed file tokens are already stored somewhere, providing a method to access the tokens instead of the file source code will be enough.

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 các entry point eval và ReflectionClass được mô tả trong issue, đồng thời điều tra xem interpreter có giữ lại source đã được eval hay các token đã được parse hay không. Công việc được xem là hoàn tất khi reflection cung cấp đủ code đã được eval để các phpdoc using statements có thể được phân giải, thông qua ReflectionClass::getFileContents() hoặc một token API tương đương.

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
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
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.