php / php/php-src

Make evaled code/tokens accessible

Offen
#8,782 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Feature Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den im Issue beschriebenen eval- und ReflectionClass-Einstiegspunkten und untersuche, ob der Interpreter evaluierten Quelltext oder geparste Tokens beibehält. Als erledigt gilt die Aufgabe, wenn die Reflection genügend Informationen über den evaluierten Code offenlegt, damit phpdoc using statements aufgelöst werden können, entweder über ReflectionClass::getFileContents() oder eine äquivalente Token-API.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.