Closed
Description
To reproduce, something like this would probably suffice:
$sourceLocator = new StringSourceLocator(
<<<'PHP'
<?php
class A {}
class B extends A {}
class C extends A {}
PHP
,
(new BetterReflection())->astLocator()
);
$reflector = new ClassReflector($sourceLocator);
// now put a breakpoint in `ClassReflector#reflect()` and notice that it is being called 4 times instead of 3:
$b = $reflector->reflect('B');
$b->getParentClassNames();
$c = $reflector->reflect('C');
$c->getParentClassNames();
This is because the various internal components don't cache the reflections.
What we can do:
- make the
ClassReflector
and theFunctionReflector
keep an internal cache by default (not so nice) - make a
CachedReflector
that caches based on the requested identifier (not so easy due to delegation logic happening in theClassReflector
internals)