@@ -506,10 +506,6 @@ public function afterOpenSslCall(string $openSslFunctionName): self
506506 /** @api */
507507 public function hasVariableType (string $ variableName ): TrinaryLogic
508508 {
509- if ($ this ->isGlobalVariable ($ variableName )) {
510- return TrinaryLogic::createYes ();
511- }
512-
513509 $ varExprString = '$ ' . $ variableName ;
514510 if (!isset ($ this ->expressionTypes [$ varExprString ])) {
515511 if ($ this ->canAnyVariableExist ()) {
@@ -541,10 +537,6 @@ public function getVariableType(string $variableName): Type
541537 }
542538 }
543539
544- if ($ this ->isGlobalVariable ($ variableName )) {
545- return new ArrayType (new BenevolentUnionType ([new IntegerType (), new StringType ()]), new MixedType (true ));
546- }
547-
548540 if ($ this ->hasVariableType ($ variableName )->no ()) {
549541 throw new UndefinedVariableException ($ this , $ variableName );
550542 }
@@ -599,11 +591,6 @@ public function getMaybeDefinedVariables(): array
599591 return $ variables ;
600592 }
601593
602- private function isGlobalVariable (string $ variableName ): bool
603- {
604- return in_array ($ variableName , self ::SUPERGLOBAL_VARIABLES , true );
605- }
606-
607594 /** @api */
608595 public function hasConstant (Name $ name ): bool
609596 {
@@ -2883,18 +2870,16 @@ public function isInFunctionExists(string $functionName): bool
28832870 public function enterClass (ClassReflection $ classReflection ): self
28842871 {
28852872 $ thisHolder = ExpressionTypeHolder::createYes (new Variable ('this ' ), new ThisType ($ classReflection ));
2886- $ constantTypes = $ this ->getConstantTypes ();
2887- $ constantTypes ['$this ' ] = $ thisHolder ;
2888- $ nativeConstantTypes = $ this ->getNativeConstantTypes ();
2889- $ nativeConstantTypes ['$this ' ] = $ thisHolder ;
2873+ $ expressionTypes = array_merge ($ this ->getSuperglobalTypes (), $ this ->getConstantTypes (), ['$this ' => $ thisHolder ]);
2874+ $ nativeExpressionTypes = array_merge ($ this ->getNativeSuperglobalTypes (), $ this ->getNativeConstantTypes (), ['$this ' => $ thisHolder ]);
28902875
28912876 return $ this ->scopeFactory ->create (
28922877 $ this ->context ->enterClass ($ classReflection ),
28932878 $ this ->isDeclareStrictTypes (),
28942879 null ,
28952880 $ this ->getNamespace (),
2896- $ constantTypes ,
2897- $ nativeConstantTypes ,
2881+ $ expressionTypes ,
2882+ $ nativeExpressionTypes ,
28982883 [],
28992884 [],
29002885 null ,
@@ -3258,8 +3243,8 @@ private function enterFunctionLike(
32583243 $ this ->isDeclareStrictTypes (),
32593244 $ functionReflection ,
32603245 $ this ->getNamespace (),
3261- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3262- array_merge ($ this ->getNativeConstantTypes (), $ nativeExpressionTypes ),
3246+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3247+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeExpressionTypes ),
32633248 $ conditionalTypes ,
32643249 );
32653250 }
@@ -3272,6 +3257,8 @@ public function enterNamespace(string $namespaceName): self
32723257 $ this ->isDeclareStrictTypes (),
32733258 null ,
32743259 $ namespaceName ,
3260+ $ this ->getSuperglobalTypes (),
3261+ $ this ->getNativeSuperglobalTypes (),
32753262 );
32763263 }
32773264
@@ -3548,8 +3535,8 @@ private function enterAnonymousFunctionWithoutReflection(
35483535 $ this ->isDeclareStrictTypes (),
35493536 $ this ->getFunction (),
35503537 $ this ->getNamespace (),
3551- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3552- array_merge ($ this ->getNativeConstantTypes (), $ nativeTypes ),
3538+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3539+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeTypes ),
35533540 [],
35543541 $ this ->inClosureBindScopeClasses ,
35553542 new TrivialParametersAcceptor (),
@@ -5807,6 +5794,36 @@ public function getConstantReflection(Type $typeWithConstant, string $constantNa
58075794 return $ typeWithConstant ->getConstant ($ constantName );
58085795 }
58095796
5797+ /** @return array<string, ExpressionTypeHolder> */
5798+ private function getSuperglobalTypes (): array
5799+ {
5800+ $ superglobalTypes = [];
5801+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5802+ foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
5803+ if (!in_array ($ exprString , $ exprStrings , true )) {
5804+ continue ;
5805+ }
5806+
5807+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
5808+ }
5809+ return $ superglobalTypes ;
5810+ }
5811+
5812+ /** @return array<string, ExpressionTypeHolder> */
5813+ private function getNativeSuperglobalTypes (): array
5814+ {
5815+ $ superglobalTypes = [];
5816+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5817+ foreach ($ this ->nativeExpressionTypes as $ exprString => $ typeHolder ) {
5818+ if (!in_array ($ exprString , $ exprStrings , true )) {
5819+ continue ;
5820+ }
5821+
5822+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
5823+ }
5824+ return $ superglobalTypes ;
5825+ }
5826+
58105827 /**
58115828 * @return array<string, ExpressionTypeHolder>
58125829 */
0 commit comments