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

False positive Strict comparison using === when treatPhpDocTypesAsCertain is false #5698

Closed
canvural opened this issue Sep 28, 2021 · 4 comments
Labels
Milestone

Comments

@canvural
Copy link
Contributor

canvural commented Sep 28, 2021

Bug report

Code snippet that reproduces the problem

<?php

function foo(int ...$foo): void {
    var_dump($foo === []);
}

foo();
foo(5);

When treatPhpDocTypesAsCertain is true there is no error reported for the above code: https://phpstan.org/r/df01e23e-636a-4d09-b106-806a14fd46ed

But when treatPhpDocTypesAsCertain is false, there is Strict comparison using === between array<int, int> and array() will always evaluate to false.: https://phpstan.org/r/16b5347b-fd04-4ae9-be7a-366f87918cac

Calling foo with no arguments is valid: https://3v4l.org/lmbDD

Expected output

No error in both cases.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 5, 2021
@phpstan-bot
Copy link
Contributor

@canvural After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-4: Strict comparison using === between array<int, int> and array() will always evaluate to false.
+4: Strict comparison using === between array<int, int> and array{} will always evaluate to false.
Full report
Line Error
4 Strict comparison using === between array<int, int> and array{} will always evaluate to false.

@phpstan-bot
Copy link
Contributor

@canvural After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-4: Strict comparison using === between array<int, int> and array() will always evaluate to false.
+PHP 8.0 (1 error)
+==========
+
+4: Strict comparison using === between array<int|string, int> and array{} will always evaluate to false.
+
+PHP 7.1 – 7.4 (1 error)
+==========
+
+4: Strict comparison using === between array<int, int> and array{} will always evaluate to false.
Full report

PHP 8.0 (1 error)

Line Error
4 `Strict comparison using === between array<int

PHP 7.1 – 7.4 (1 error)

Line Error
4 Strict comparison using === between array<int, int> and array{} will always evaluate to false.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a5447db

@github-actions
Copy link

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 Feb 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants