Skip to content

Service constructor: add native support for strict array type. #277

@janbarasek

Description

@janbarasek

Hello,

In the DI service entry, I can request a collection of services that meet the same interface.

For example:

/**  * @param OrderPaymentGatewayInterface[] $providers  */ public function __construct(array $providers) { ... }

If I am using PhpStan level 9 and want to specify the exact key type in an array, DIC cannot inject services:

/**  * @param array<int, OrderPaymentGatewayInterface> $providers  */ public function __construct(array $providers) { ... }

The challenge is to add native support for composite array notation with exact key definition. In the first phase, I propose to support only the int key type and mark all others as unsupported.

Why support this notation? Much more strict type within the service.

Thanks.

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