Skip to content

Return type of filter_var() with array argument FILTER_REQUIRE_ARRAY option #11863

@thomascorthals

Description

@thomascorthals

Bug report

When calling filter_var() with an array<int, string> argument and the FILTER_REQUIRE_ARRAY option, PHPStan assumes it can return array<int, string>|false. In reality it always returns an array. If every element of the input array is invalid the returned array will only contain false values, but it's still an array. The return type in this case should be array<int, string|false>.

Code snippet that reproduces the problem

https://phpstan.org/r/3be12e81-de1e-4918-b251-2f41dbfa2c2d

Expected output

No error as filter_var() always returns an array in this case.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions