8000 Make evaled code/tokens accessible · Issue #8782 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Make evaled code/tokens accessible #8782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mvorisek opened this issue Jun 14, 2022 · 1 comment
Open

Make evaled code/tokens accessible #8782

mvorisek opened this issue Jun 14, 2022 · 1 comment

Comments

@mvorisek
Copy link
Contributor
mvorisek commented Jun 14, 2022

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.

@bwoebi
Copy link
Member
bwoebi commented Jun 15, 2022

If the parsed file tokens are already stored somewhere

They are not. The file, token and AST information do all not survive compilation stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0