5353use PHPStan \TrinaryLogic ;
5454use PHPStan \Type \FileTypeMapper ;
5555use PHPStan \Type \Generic \TemplateTypeMap ;
56+ use PHPStan \Type \IntegerRangeType ;
5657use PHPStan \Type \Type ;
58+ use PHPStan \Type \VerbosityLevel ;
5759use function array_key_exists ;
5860use function array_key_first ;
5961use function array_map ;
@@ -372,8 +374,15 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
372374 throw new ConstantNotFoundException ((string ) $ nameNode );
373375 }
374376
375- if (array_key_exists ($ constantName , $ this ->cachedConstants )) {
376- return $ this ->cachedConstants [$ constantName ];
377+ $ phpVersionType = null ;
378+ $ cacheKey = $ constantName ;
379+ if ($ namespaceAnswerer instanceof Scope) {
380+ $ phpVersionType = $ namespaceAnswerer ->getPhpVersion ()->getType ();
381+ $ cacheKey = $ constantName . '- ' . $ phpVersionType ->describe (VerbosityLevel::cache ());
382+ }
383+
384+ if (array_key_exists ($ cacheKey , $ this ->cachedConstants )) {
385+ return $ this ->cachedConstants [$ cacheKey ];
377386 }
378387
379388 $ constantReflection = $ this ->reflector ->reflectConstant ($ constantName );
@@ -399,7 +408,11 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
399408 $ patch = $ matches [3 ] ?? 0 ;
400409 $ versionId = sprintf ('%d%02d%02d ' , $ major , $ minor , $ patch );
401410
402- $ isDeprecated = $ this ->phpVersion ->getVersionId () >= $ versionId ;
411+ if ($ phpVersionType !== null ) {
412+ $ isDeprecated = IntegerRangeType::fromInterval ((int ) $ versionId , null )->isSuperTypeOf ($ phpVersionType )->yes ();
413+ } else {
414+ $ isDeprecated = $ this ->phpVersion ->getVersionId () >= $ versionId ;
415+ }
403416 } else {
404417 // filter raw version number messages like in
405418 // https://github.com/JetBrains/phpstorm-stubs/blob/9608c953230b08f07b703ecfe459cc58d5421437/filter/filter.php#L478
@@ -412,7 +425,7 @@ public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAn
412425 $ isDeprecated = $ constantReflection ->isDeprecated ();
413426 }
414427
415- return $ this ->cachedConstants [$ constantName ] = new RuntimeConstantReflection (
428+ return $ this ->cachedConstants [$ cacheKey ] = new RuntimeConstantReflection (
416429 $ constantName ,
417430 $ constantValueType ,
418431 $ fileName ,
0 commit comments