@@ -78,7 +78,7 @@ final class BetterReflectionProvider implements ReflectionProvider
7878 /** @var ClassReflection[] */
7979 private static array $ anonymousClasses = [];
8080
81- /** @var array<string, ConstantReflection> */
81+ /** @var array<string, array<string, ConstantReflection> > */
8282 private array $ cachedConstants = [];
8383
8484 /**
@@ -375,14 +375,18 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
375375 }
376376
377377 $ phpVersionType = null ;
378- $ cacheKey = $ constantName ;
378+ $ versionKey = ' current_version ' ;
379379 if ($ namespaceAnswerer instanceof Scope) {
380380 $ phpVersionType = $ namespaceAnswerer ->getPhpVersion ()->getType ();
381- $ cacheKey = $ constantName . ' - ' . $ phpVersionType ->describe (VerbosityLevel::cache ());
381+ $ versionKey = $ phpVersionType ->describe (VerbosityLevel::cache ());
382382 }
383383
384- if (array_key_exists ($ cacheKey , $ this ->cachedConstants )) {
385- return $ this ->cachedConstants [$ cacheKey ];
384+ if (!array_key_exists ($ versionKey , $ this ->cachedConstants )) {
385+ $ this ->cachedConstants [$ versionKey ] = [];
386+ }
387+
388+ if (array_key_exists ($ constantName , $ this ->cachedConstants [$ versionKey ])) {
389+ return $ this ->cachedConstants [$ versionKey ][$ constantName ];
386390 }
387391
388392 $ constantReflection = $ this ->reflector ->reflectConstant ($ constantName );
@@ -425,7 +429,7 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
425429 $ isDeprecated = $ constantReflection ->isDeprecated ();
426430 }
427431
428- return $ this ->cachedConstants [$ cacheKey ] = new RuntimeConstantReflection (
432+ return $ this ->cachedConstants [$ versionKey ][ $ constantName ] = new RuntimeConstantReflection (
429433 $ constantName ,
430434 $ constantValueType ,
431435 $ fileName ,
0 commit comments