diff --git a/src/Reflection/ParametersAcceptorSelector.php b/src/Reflection/ParametersAcceptorSelector.php index ef68dc20f1..e665f02567 100644 --- a/src/Reflection/ParametersAcceptorSelector.php +++ b/src/Reflection/ParametersAcceptorSelector.php @@ -785,10 +785,18 @@ private static function getCurlOptValueType(int $curlOpt): ?Type } } + $intArrayStringKeysConstants = [ + 'CURLOPT_HTTPHEADER', + ]; + foreach ($intArrayStringKeysConstants as $constName) { + if (defined($constName) && constant($constName) === $curlOpt) { + return new ArrayType(new IntegerType(), new StringType()); + } + } + $arrayConstants = [ 'CURLOPT_CONNECT_TO', 'CURLOPT_HTTP200ALIASES', - 'CURLOPT_HTTPHEADER', 'CURLOPT_POSTQUOTE', 'CURLOPT_PROXYHEADER', 'CURLOPT_QUOTE', diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index b1f15bbc35..a11dcefb44 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -1208,7 +1208,7 @@ public function testCurlSetOpt(): void 14, ], [ - 'Parameter #3 $value of function curl_setopt expects array, int given.', + 'Parameter #3 $value of function curl_setopt expects array, int given.', 15, ], [ @@ -1235,6 +1235,10 @@ public function testCurlSetOpt(): void 'Parameter #3 $value of function curl_setopt expects array|string, int given.', 26, ], + [ + 'Parameter #3 $value of function curl_setopt expects array, array given.', + 65, + ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/curl_setopt.php b/tests/PHPStan/Rules/Functions/data/curl_setopt.php index f5d33fe43d..208a7087f1 100644 --- a/tests/PHPStan/Rules/Functions/data/curl_setopt.php +++ b/tests/PHPStan/Rules/Functions/data/curl_setopt.php @@ -55,4 +55,18 @@ public function allGood(string $url, array $header) { curl_setopt($curl, CURLOPT_PROXY, ''); curl_setopt($curl, CURLOPT_PRIVATE, ''); } + + public function bug9263() { + $curl = curl_init(); + + $header_dictionary = [ + 'Accept' => 'application/json', + ]; + curl_setopt($curl, CURLOPT_HTTPHEADER, $header_dictionary); + + $header_list = [ + 'Accept: application/json', + ]; + curl_setopt($curl, CURLOPT_HTTPHEADER, $header_list); + } }