Skip to content

Feature suggestion: useless array_filter #6840

@leongersen

Description

@leongersen

Feature request

For array_filter with no callback, PHPStan could report useless calls if the type for the array does not contain any empty values (null/==false). This could indicate an incorrect type for the array or another oversight.

For example:

array_filter([0,1,2]);
array_filter([1,2]); // report
array_filter(['', 'hello']);
array_filter([false, true]);
array_filter([new \stdClass()]); // report

/** \stdClass[] $arr */
array_filter($arr); // report

I could work on this if you're interested in the feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions