Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oschwald opened this issue Mar 28, 2022 · 5 comments · Fixed by phpstan/phpstan-src#1170
Closed
Labels
Milestone

Comments

@oschwald
Copy link

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.

@mergeable
Copy link

mergeable bot commented Mar 28, 2022

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@oschwald
Copy link
Author

phpstan.org reproduction.

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#1170

@github-actions
Copy link

github-actions bot commented May 6, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants