diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 9ffade9f9c..b51c0c0236 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -2354,7 +2354,7 @@ static function (): void { $functionReflection !== null && in_array($functionReflection->getName(), ['fopen', 'file_get_contents'], true) ) { - $scope = $scope->assignVariable('http_response_header', new ArrayType(new IntegerType(), new StringType()), new ArrayType(new IntegerType(), new StringType())); + $scope = $scope->assignVariable('http_response_header', AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType())), new ArrayType(new IntegerType(), new StringType())); } if ( diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index ef657dc012..b22631d986 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1441,6 +1441,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/preserve-large-constant-array.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9397.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10080.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/http-response-header.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-error-log.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/falsy-isset.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/falsey-coalesce.php'); diff --git a/tests/PHPStan/Analyser/data/http-response-header.php b/tests/PHPStan/Analyser/data/http-response-header.php new file mode 100644 index 0000000000..aa39899630 --- /dev/null +++ b/tests/PHPStan/Analyser/data/http-response-header.php @@ -0,0 +1,8 @@ +', $http_response_header); +assertNativeType('array', $http_response_header);