Skip to content

Incorrect "negated boolean expression is always false" with boolean comparison of variadic parameter and "treatPhpDocTypesAsCertain: false" #6393

@ilmiont

Description

@ilmiont

Bug report

Reproduced in latest PHPStan v1.4.1.

When a function has a variadic parameter, that parameter is typed as an object, and treatPhpDocTypesAsCertain: false is used, PHPStan seems to incorrectly believe that the array created from the variadic parameter values will be non-empty.

Code snippet that reproduces the problem

Playground test case

https://phpstan.org/r/9c91108d-fdf7-44a0-8710-4549a756684d

Expected output

No error should be thrown on line 10. It is valid to call sayHello() with no parameters, and then an empty $people array would be created.

If you enable the "Treat PHPDoc types as certain" flag, the correct behaviour is used.

In addition, if you change the type of $people to a scalar type, the correct behaviour is used.

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

PHPStan has transformed the PHP community and my confidence in my work. Huge thanks to all involved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions