You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
ilmiont
changed the title
Incorrect "negated boolean expression is always false" with variadic parameter and "treatPhpDocTypesAsCertain: false"
Incorrect "negated boolean expression is always false" when checking if array created from variadic parameter is empty with "treatPhpDocTypesAsCertain: false"
Jan 17, 2022
ilmiont
changed the title
Incorrect "negated boolean expression is always false" when checking if array created from variadic parameter is empty with "treatPhpDocTypesAsCertain: false"
Incorrect "negated boolean expression is always false" with boolean comparison of variadic parameter and "treatPhpDocTypesAsCertain: false"
Jan 17, 2022
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 thearray
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.
The text was updated successfully, but these errors were encountered: