@@ -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 {
@@ -2886,18 +2873,16 @@ public function isInFunctionExists(string $functionName): bool
28862873 public function enterClass (ClassReflection $ classReflection ): self
28872874 {
28882875 $ thisHolder = ExpressionTypeHolder::createYes (new Variable ('this ' ), new ThisType ($ classReflection ));
2889- $ constantTypes = $ this ->getConstantTypes ();
2890- $ constantTypes ['$this ' ] = $ thisHolder ;
2891- $ nativeConstantTypes = $ this ->getNativeConstantTypes ();
2892- $ nativeConstantTypes ['$this ' ] = $ thisHolder ;
2876+ $ expressionTypes = array_merge ($ this ->getSuperglobalTypes (), $ this ->getConstantTypes (), ['$this ' => $ thisHolder ]);
2877+ $ nativeExpressionTypes = array_merge ($ this ->getNativeSuperglobalTypes (), $ this ->getNativeConstantTypes (), ['$this ' => $ thisHolder ]);
28932878
28942879 return $ this ->scopeFactory ->create (
28952880 $ this ->context ->enterClass ($ classReflection ),
28962881 $ this ->isDeclareStrictTypes (),
28972882 null ,
28982883 $ this ->getNamespace (),
2899- $ constantTypes ,
2900- $ nativeConstantTypes ,
2884+ $ expressionTypes ,
2885+ $ nativeExpressionTypes ,
29012886 [],
29022887 [],
29032888 null ,
@@ -3264,8 +3249,8 @@ private function enterFunctionLike(
32643249 $ this ->isDeclareStrictTypes (),
32653250 $ functionReflection ,
32663251 $ this ->getNamespace (),
3267- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3268- array_merge ($ this ->getNativeConstantTypes (), $ nativeExpressionTypes ),
3252+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3253+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeExpressionTypes ),
32693254 $ conditionalTypes ,
32703255 );
32713256 }
@@ -3278,6 +3263,8 @@ public function enterNamespace(string $namespaceName): self
32783263 $ this ->isDeclareStrictTypes (),
32793264 null ,
32803265 $ namespaceName ,
3266+ $ this ->getSuperglobalTypes (),
3267+ $ this ->getNativeSuperglobalTypes (),
32813268 );
32823269 }
32833270
@@ -3554,8 +3541,8 @@ private function enterAnonymousFunctionWithoutReflection(
35543541 $ this ->isDeclareStrictTypes (),
35553542 $ this ->getFunction (),
35563543 $ this ->getNamespace (),
3557- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3558- array_merge ($ this ->getNativeConstantTypes (), $ nativeTypes ),
3544+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3545+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeTypes ),
35593546 [],
35603547 $ this ->inClosureBindScopeClasses ,
35613548 new TrivialParametersAcceptor (),
@@ -5877,6 +5864,36 @@ public function getConstantReflection(Type $typeWithConstant, string $constantNa
58775864 return $ typeWithConstant ->getConstant ($ constantName );
58785865 }
58795866
5867+ /** @return array<string, ExpressionTypeHolder> */
5868+ private function getSuperglobalTypes (): array
5869+ {
5870+ $ superglobalTypes = [];
5871+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5872+ foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
5873+ if (!in_array ($ exprString , $ exprStrings , true )) {
5874+ continue ;
5875+ }
5876+
5877+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
5878+ }
5879+ return $ superglobalTypes ;
5880+ }
5881+
5882+ /** @return array<string, ExpressionTypeHolder> */
5883+ private function getNativeSuperglobalTypes (): array
5884+ {
5885+ $ superglobalTypes = [];
5886+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5887+ foreach ($ this ->nativeExpressionTypes as $ exprString => $ typeHolder ) {
5888+ if (!in_array ($ exprString , $ exprStrings , true )) {
5889+ continue ;
5890+ }
5891+
5892+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
5893+ }
5894+ return $ superglobalTypes ;
5895+ }
5896+
58805897 /**
58815898 * @return array<string, ExpressionTypeHolder>
58825899 */
0 commit comments