@@ -513,10 +513,6 @@ public function afterOpenSslCall(string $openSslFunctionName): self
513513 /** @api */
514514 public function hasVariableType (string $ variableName ): TrinaryLogic
515515 {
516- if ($ this ->isGlobalVariable ($ variableName )) {
517- return TrinaryLogic::createYes ();
518- }
519-
520516 $ varExprString = '$ ' . $ variableName ;
521517 if (!isset ($ this ->expressionTypes [$ varExprString ])) {
522518 if ($ this ->canAnyVariableExist ()) {
@@ -548,10 +544,6 @@ public function getVariableType(string $variableName): Type
548544 }
549545 }
550546
551- if ($ this ->isGlobalVariable ($ variableName )) {
552- return new ArrayType (new BenevolentUnionType ([new IntegerType (), new StringType ()]), new MixedType (true ));
553- }
554-
555547 if ($ this ->hasVariableType ($ variableName )->no ()) {
556548 throw new UndefinedVariableException ($ this , $ variableName );
557549 }
@@ -606,11 +598,6 @@ public function getMaybeDefinedVariables(): array
606598 return $ variables ;
607599 }
608600
609- private function isGlobalVariable (string $ variableName ): bool
610- {
611- return in_array ($ variableName , self ::SUPERGLOBAL_VARIABLES , true );
612- }
613-
614601 /** @api */
615602 public function hasConstant (Name $ name ): bool
616603 {
@@ -2893,18 +2880,16 @@ public function isInFunctionExists(string $functionName): bool
28932880 public function enterClass (ClassReflection $ classReflection ): self
28942881 {
28952882 $ thisHolder = ExpressionTypeHolder::createYes (new Variable ('this ' ), new ThisType ($ classReflection ));
2896- $ constantTypes = $ this ->getConstantTypes ();
2897- $ constantTypes ['$this ' ] = $ thisHolder ;
2898- $ nativeConstantTypes = $ this ->getNativeConstantTypes ();
2899- $ nativeConstantTypes ['$this ' ] = $ thisHolder ;
2883+ $ expressionTypes = array_merge ($ this ->getSuperglobalTypes (), $ this ->getConstantTypes (), ['$this ' => $ thisHolder ]);
2884+ $ nativeExpressionTypes = array_merge ($ this ->getNativeSuperglobalTypes (), $ this ->getNativeConstantTypes (), ['$this ' => $ thisHolder ]);
29002885
29012886 return $ this ->scopeFactory ->create (
29022887 $ this ->context ->enterClass ($ classReflection ),
29032888 $ this ->isDeclareStrictTypes (),
29042889 null ,
29052890 $ this ->getNamespace (),
2906- $ constantTypes ,
2907- $ nativeConstantTypes ,
2891+ $ expressionTypes ,
2892+ $ nativeExpressionTypes ,
29082893 [],
29092894 [],
29102895 null ,
@@ -3298,8 +3283,8 @@ private function enterFunctionLike(
32983283 $ this ->isDeclareStrictTypes (),
32993284 $ functionReflection ,
33003285 $ this ->getNamespace (),
3301- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3302- array_merge ($ this ->getNativeConstantTypes (), $ nativeExpressionTypes ),
3286+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3287+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeExpressionTypes ),
33033288 $ conditionalTypes ,
33043289 );
33053290 }
@@ -3312,6 +3297,8 @@ public function enterNamespace(string $namespaceName): self
33123297 $ this ->isDeclareStrictTypes (),
33133298 null ,
33143299 $ namespaceName ,
3300+ $ this ->getSuperglobalTypes (),
3301+ $ this ->getNativeSuperglobalTypes (),
33153302 );
33163303 }
33173304
@@ -3588,8 +3575,8 @@ private function enterAnonymousFunctionWithoutReflection(
35883575 $ this ->isDeclareStrictTypes (),
35893576 $ this ->getFunction (),
35903577 $ this ->getNamespace (),
3591- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
3592- array_merge ($ this ->getNativeConstantTypes (), $ nativeTypes ),
3578+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
3579+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeTypes ),
35933580 [],
35943581 $ this ->inClosureBindScopeClasses ,
35953582 new TrivialParametersAcceptor (),
@@ -5987,6 +5974,36 @@ public function getConstantReflection(Type $typeWithConstant, string $constantNa
59875974 return $ typeWithConstant ->getConstant ($ constantName );
59885975 }
59895976
5977+ /** @return array<string, ExpressionTypeHolder> */
5978+ private function getSuperglobalTypes (): array
5979+ {
5980+ $ superglobalTypes = [];
5981+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5982+ foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
5983+ if (!in_array ($ exprString , $ exprStrings , true )) {
5984+ continue ;
5985+ }
5986+
5987+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
5988+ }
5989+ return $ superglobalTypes ;
5990+ }
5991+
5992+ /** @return array<string, ExpressionTypeHolder> */
5993+ private function getNativeSuperglobalTypes (): array
5994+ {
5995+ $ superglobalTypes = [];
5996+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
5997+ foreach ($ this ->nativeExpressionTypes as $ exprString => $ typeHolder ) {
5998+ if (!in_array ($ exprString , $ exprStrings , true )) {
5999+ continue ;
6000+ }
6001+
6002+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
6003+ }
6004+ return $ superglobalTypes ;
6005+ }
6006+
59906007 /**
59916008 * @return array<string, ExpressionTypeHolder>
59926009 */
0 commit comments