Skip to content

Binding scalars to generics #3769

@MidnightDesign

Description

@MidnightDesign

It would be great if generics supported binding scalars. Here's a use case:

/**
 * @template K of array-key
 * @param array<K, int> $in
 * @return array<K, string>
 */
function stringValues(array $in): array {
    return array_map(fn (int $int): string => (string) $int, $in);
}

Currently, this gives me a

PHPDoc tag @template K for function stringValues() with bound type (int|string) is not supported.

See https://phpstan.org/r/f80b7892-415f-4c38-a63b-37b885d1b6ae

I have read somewhere that this is being considered, but I couldn't find an issue for it and I wanted to provide a use case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions