[php-src] Issue #8782: Make evaled code/tokens accessible
| From: | mvorisek | Date: | Tue, 14 Jun 2022 21:55:59 +0000 |
| Subject: | [php-src] Issue #8782: Make evaled code/tokens accessible | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241735@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8782
Author: 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);
```
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.