Skip to content

Support for @template T of array #3931

@MidnightDesign

Description

@MidnightDesign

It should be possible to "extend" (of) Arrays. Use case:

/**
 * @template T of array
 * @param T $arr
 * @return T & array{mykey: int}
 */
function addSomeKey(array $arr, int $value): array {
	$arr['mykey'] = $value;
	return $arr;
}

Playground: https://phpstan.org/r/2a391b38-912d-4ea5-a71a-a1fab833d2f8

Right now, this produces multiple errors, the root problem being:

PHPDoc tag @template T for function addSomeKey() with bound type array is not supported.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions