Skip to content

Incorrect return type on curl_getinfo($ch, CURLINFO_CONTENT_TYPE)  #6929

@oschwald

Description

@oschwald

Bug report

As of PHPStan 1.5.0 and 1.5.1, the return type on curl_getinfo($ch, CURLINFO_CONTENT_TYPE) seems to string even though false will be returned when the header is not present.

I did glance at the PR that added the dynamic types and the author seems to have intended to handle this case. It was not immediately clear to me why it wasn't working.

Code snippet that reproduces the problem

For instance, the following code results in an error:

        $contentType = curl_getinfo($curl, \CURLINFO_CONTENT_TYPE);


        return [
            $statusCode,
            ($contentType === false ? null : $contentType),
            ...
        ]

See this link.

Output:

 ------ -------------------------------------------------------------------------------------
  Line   src/WebService/Http/CurlRequest.php
 ------ -------------------------------------------------------------------------------------
  132    Strict comparison using === between string and false will always evaluate to false.
 ------ -------------------------------------------------------------------------------------

Build failure.

Expected output

I expect no output from this code.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan is extremely helpful in finding issues without running and testing the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions