Skip to content

Require value types for nested iterable types #5148

@spawnia

Description

@spawnia

Feature request

I think it is great that PHPStan requires specification of the value type within iterable types. This feature has prevented a lot of bugs and made our codebase much more understandable. It would be great if it could be taken even further: specifying the value type should also be required for nested iterables.

For the following example, PHPStan should complain that the value type for the nested iterable is missing:

/**
 * @param array<iterable> $bar
 */
function foo(array $bar): void {}

This should extend all the way down if more levels of nesting are used. While it is increasingly more work to write out nested types, I found that those complex parts of our code are also the most error prone.

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

Just yesterday, I was able to find 2 bugs in our codebase by adding a bunch of array shapes 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions