Skip to content

array_filter(), array_map() and array_reduce() should be considered pure functions #11101

@zonuexe

Description

@zonuexe

Bug report

The following calls have no side effects but are not reported as no effect:

array_filter($array, 'is_string');
array_map('is_string', $array);
array_reduce($array, function ($carry, $item) {
    return $carry + $item;
}, 0);

Code snippet that reproduces the problem

https://phpstan.org/r/cebff095-ed17-4f7d-92e0-771a7eed998c

Expected output

Call to function array_filter() on a separate line has no effect.
Call to function array_map() on a separate line has no effect.
Call to function array_reduce() on a separate line has no effect.

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

Today I demoed PHPStan 1.11 and PHPStan Pro at the PHP Meetup in Tokyo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions