@@ -188,7 +188,6 @@ public function __construct(
188188 private ?Scope $ parentScope = null ,
189189 private bool $ nativeTypesPromoted = false ,
190190 private bool $ explicitMixedInUnknownGenericNew = false ,
191- private bool $ explicitMixedForGlobalVariables = false ,
192191 )
193192 {
194193 if ($ namespace === '' ) {
@@ -466,10 +465,6 @@ public function afterOpenSslCall(string $openSslFunctionName): self
466465 /** @api */
467466 public function hasVariableType (string $ variableName ): TrinaryLogic
468467 {
469- if ($ this ->isGlobalVariable ($ variableName )) {
470- return TrinaryLogic::createYes ();
471- }
472-
473468 $ varExprString = '$ ' . $ variableName ;
474469 if (!isset ($ this ->expressionTypes [$ varExprString ])) {
475470 if ($ this ->canAnyVariableExist ()) {
@@ -500,10 +495,6 @@ public function getVariableType(string $variableName): Type
500495 }
501496 }
502497
503- if ($ this ->isGlobalVariable ($ variableName )) {
504- return new ArrayType (new StringType (), new MixedType ($ this ->explicitMixedForGlobalVariables ));
505- }
506-
507498 if ($ this ->hasVariableType ($ variableName )->no ()) {
508499 throw new UndefinedVariableException ($ this , $ variableName );
509500 }
@@ -537,21 +528,6 @@ public function getDefinedVariables(): array
537528 return $ variables ;
538529 }
539530
540- private function isGlobalVariable (string $ variableName ): bool
541- {
542- return in_array ($ variableName , [
543- 'GLOBALS ' ,
544- '_SERVER ' ,
545- '_GET ' ,
546- '_POST ' ,
547- '_FILES ' ,
548- '_COOKIE ' ,
549- '_SESSION ' ,
550- '_REQUEST ' ,
551- '_ENV ' ,
552- ], true );
553- }
554-
555531 /** @api */
556532 public function hasConstant (Name $ name ): bool
557533 {
@@ -2133,7 +2109,6 @@ public function doNotTreatPhpDocTypesAsCertain(): Scope
21332109 $ this ->parentScope ,
21342110 false ,
21352111 $ this ->explicitMixedInUnknownGenericNew ,
2136- $ this ->explicitMixedForGlobalVariables ,
21372112 );
21382113 }
21392114
@@ -2430,12 +2405,8 @@ public function enterClass(ClassReflection $classReflection): self
24302405 $ this ->isDeclareStrictTypes (),
24312406 null ,
24322407 $ this ->getNamespace (),
2433- array_merge ($ this ->getConstantTypes (), [
2434- '$this ' => $ thisHolder ,
2435- ]),
2436- array_merge ($ this ->getNativeConstantTypes (), [
2437- '$this ' => $ thisHolder ,
2438- ]),
2408+ array_merge ($ this ->getSuperglobalTypes (), $ this ->getConstantTypes (), ['$this ' => $ thisHolder ]),
2409+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this ->getNativeConstantTypes (), ['$this ' => $ thisHolder ]),
24392410 [],
24402411 null ,
24412412 null ,
@@ -2671,8 +2642,8 @@ private function enterFunctionLike(
26712642 $ this ->isDeclareStrictTypes (),
26722643 $ functionReflection ,
26732644 $ this ->getNamespace (),
2674- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
2675- array_merge ($ this ->getNativeConstantTypes (), $ nativeExpressionTypes ),
2645+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
2646+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeExpressionTypes ),
26762647 );
26772648 }
26782649
@@ -2684,6 +2655,8 @@ public function enterNamespace(string $namespaceName): self
26842655 $ this ->isDeclareStrictTypes (),
26852656 null ,
26862657 $ namespaceName ,
2658+ $ this ->getSuperglobalTypes (),
2659+ $ this ->getNativeSuperglobalTypes (),
26872660 );
26882661 }
26892662
@@ -2907,8 +2880,8 @@ private function enterAnonymousFunctionWithoutReflection(
29072880 $ this ->isDeclareStrictTypes (),
29082881 $ this ->getFunction (),
29092882 $ this ->getNamespace (),
2910- array_merge ($ this ->getConstantTypes (), $ expressionTypes ),
2911- array_merge ($ this ->getNativeConstantTypes (), $ nativeTypes ),
2883+ array_merge ($ this ->getSuperglobalTypes (), $ this -> getConstantTypes (), $ expressionTypes ),
2884+ array_merge ($ this ->getNativeSuperglobalTypes (), $ this -> getNativeConstantTypes (), $ nativeTypes ),
29122885 [],
29132886 $ this ->inClosureBindScopeClass ,
29142887 new TrivialParametersAcceptor (),
@@ -4990,4 +4963,34 @@ private function getNativeConstantTypes(): array
49904963 return $ constantTypes ;
49914964 }
49924965
4966+ /** @return array<string, ExpressionTypeHolder> */
4967+ private function getSuperglobalTypes (): array
4968+ {
4969+ $ superglobalTypes = [];
4970+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
4971+ foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
4972+ if (!in_array ($ exprString , $ exprStrings , true )) {
4973+ continue ;
4974+ }
4975+
4976+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
4977+ }
4978+ return $ superglobalTypes ;
4979+ }
4980+
4981+ /** @return array<string, ExpressionTypeHolder> */
4982+ private function getNativeSuperglobalTypes (): array
4983+ {
4984+ $ superglobalTypes = [];
4985+ $ exprStrings = ['$GLOBALS ' , '$_SERVER ' , '$_GET ' , '$_POST ' , '$_FILES ' , '$_COOKIE ' , '$_SESSION ' , '$_REQUEST ' , '$_ENV ' ];
4986+ foreach ($ this ->nativeExpressionTypes as $ exprString => $ typeHolder ) {
4987+ if (!in_array ($ exprString , $ exprStrings , true )) {
4988+ continue ;
4989+ }
4990+
4991+ $ superglobalTypes [$ exprString ] = $ typeHolder ;
4992+ }
4993+ return $ superglobalTypes ;
4994+ }
4995+
49934996}
0 commit comments