Skip to content

Commit 316630e

Browse files
authored
Ensure http_response_header is a list<string>
1 parent 57b6434 commit 316630e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ static function (): void {
23542354
$functionReflection !== null
23552355
&& in_array($functionReflection->getName(), ['fopen', 'file_get_contents'], true)
23562356
) {
2357-
$scope = $scope->assignVariable('http_response_header', new ArrayType(new IntegerType(), new StringType()), new ArrayType(new IntegerType(), new StringType()));
2357+
$scope = $scope->assignVariable('http_response_header', AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType())), new ArrayType(new IntegerType(), new StringType()));
23582358
}
23592359

23602360
if (

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ public function dataFileAsserts(): iterable
14411441
yield from $this->gatherAssertTypes(__DIR__ . '/data/preserve-large-constant-array.php');
14421442
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9397.php');
14431443
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10080.php');
1444+
yield from $this->gatherAssertTypes(__DIR__ . '/data/http-response-header.php');
14441445
yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-error-log.php');
14451446
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsy-isset.php');
14461447
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsey-coalesce.php');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
use function PHPStan\Testing\assertNativeType;
5+
6+
file_get_contents('https://example.org');
7+
assertType('list<string>', $http_response_header);
8+
assertNativeType('array<int, string>', $http_response_header);

0 commit comments

Comments
 (0)