Roave / BetterReflection

:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
MIT License
1.19k stars 131 forks source link

`PhpStormStubsSourceStubber` calls into application autoloader #1415

Closed staabm closed 7 months ago

staabm commented 7 months ago

while debugging today, I realized that when BetterReflection is building up its reflection knowledge based on phpstorm stubs, it is invoking application autoloaders.

I found stacktraces like

grafik

in which you can see the top-level frame Rocket::autoload. thats my application autoloader which is registered via phpstan bootstrap file.

my questions:

I came to this question, because our application autoloading needs todo some gymnastics and it is invoked a lot for all kind of classes which BetterReflection is locating while parsing stub files.

looking deeper it might even be the case this only happens from within PHPStan.. not sure yet

kukulich commented 7 months ago

should BetterReflection trigger autoloading while analyzing phpstorm stubs? if autoloading is really needed, should better reflection isolate the autoloading involved from side-effects like a application level autoloader?

The autoload is not intentional. It looks it's triggered by defined.

We use updateConstantValue because values in stubs are not actual or are different on different PHP versions or operating systems.

staabm commented 7 months ago

It looks it's triggered by defined.

I wasn't aware defined can trigger autoloading, but you are right:

https://3v4l.org/pMmLA

kukulich commented 7 months ago

We can probably use get_defined_constants: https://3v4l.org/r3O9o

staabm commented 7 months ago

@kukulich I found a way on how it could work, please have a look: https://github.com/Roave/BetterReflection/pull/1416

kukulich commented 7 months ago

@staabm I think it's very nice solution 👍