diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index da080af2e9f..ecb5ea40003 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -2446,8 +2446,8 @@ public function enterClass(ClassReflection $classReflection): self $this->isDeclareStrictTypes(), null, $this->getNamespace(), - array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), ['$this' => $thisHolder]), - array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), ['$this' => $thisHolder]), + array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), ['$this' => $thisHolder]), + array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), ['$this' => $thisHolder]), [], null, null, @@ -2683,8 +2683,8 @@ private function enterFunctionLike( $this->isDeclareStrictTypes(), $functionReflection, $this->getNamespace(), - array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), $expressionTypes), - array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), $nativeExpressionTypes), + array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), $expressionTypes), + array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), $nativeExpressionTypes), ); } @@ -2696,8 +2696,8 @@ public function enterNamespace(string $namespaceName): self $this->isDeclareStrictTypes(), null, $namespaceName, - $this->getSuperglobalExpressionTypes(), - $this->getSuperglobalExpressionTypes(), + $this->getSuperglobalTypes(), + $this->getNativeSuperglobalTypes(), ); } @@ -2921,8 +2921,8 @@ private function enterAnonymousFunctionWithoutReflection( $this->isDeclareStrictTypes(), $this->getFunction(), $this->getNamespace(), - array_merge($this->getSuperglobalExpressionTypes(), $this->getConstantTypes(), $expressionTypes), - array_merge($this->getSuperglobalExpressionTypes(), $this->getNativeConstantTypes(), $nativeTypes), + array_merge($this->getSuperglobalTypes(), $this->getConstantTypes(), $expressionTypes), + array_merge($this->getNativeSuperglobalTypes(), $this->getNativeConstantTypes(), $nativeTypes), [], $this->inClosureBindScopeClass, new TrivialParametersAcceptor(), @@ -4994,18 +4994,33 @@ private function getNativeConstantTypes(): array } /** @return array */ - private function getSuperglobalExpressionTypes(): array + private function getSuperglobalTypes(): array { - $superglobalExpressionTypes = []; + $superglobalTypes = []; $exprStrings = ['$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV']; foreach ($this->expressionTypes as $exprString => $typeHolder) { if (!in_array($exprString, $exprStrings, true)) { continue; } - $superglobalExpressionTypes[$exprString] = $typeHolder; + $superglobalTypes[$exprString] = $typeHolder; } - return $superglobalExpressionTypes; + return $superglobalTypes; + } + + /** @return array */ + private function getNativeSuperglobalTypes(): array + { + $superglobalTypes = []; + $exprStrings = ['$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV']; + foreach ($this->nativeExpressionTypes as $exprString => $typeHolder) { + if (!in_array($exprString, $exprStrings, true)) { + continue; + } + + $superglobalTypes[$exprString] = $typeHolder; + } + return $superglobalTypes; } }