Skip to content

Make evaled code/tokens accessible #8782

Open
@mvorisek

Description

@mvorisek

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions