Skip to content

array_reduce could infer the precise type of the $initial argument within the callable and in the return type #7280

@gnutix

Description

@gnutix

Feature request

Hello there. While adding some types and types' tests for a bunch of Functional-related functions in our codebase, I noticed that array_reduce does not infer the type of the initial variable within the callback : https://phpstan.org/r/c1273a00-7b17-4745-afd4-1de4002183ff

It would be especially useful in situations like the code above, where the reduce operation is used to "fill a bucket" having many entries.

The playground above also shows that the return value could probably be more precise as well.

(I don't currently have the time to work on an implementation, but maybe someone will.)

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

(I have a bunch of small issues to create, sorry if I don't come up with something new for each of them 🙏 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions