Skip to content

Spreading an associative array into a generic function/method call may restrict optional arguments to their default values. #12363

Closed

Description

@sebkehr

Bug report

When spreading an associative array into a function or method call the type of a generic optional argument may be unexpectedly restricted to its default value.

Code snippet that reproduces the problem

https://phpstan.org/r/8954c7b1-5966-4015-9e6e-59054cb17c1e

Expected output

Passing any value fitting the template bound should be valid - just like when there is no preceding required argument: https://phpstan.org/r/4a4250d2-ab86-47d5-ad1f-cde664d47281.

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

Yes, for sure!

We at @sport-iat heavily rely on PHPStan to statically validate our code against self-generated array shape typedefs (from JSON schema definitions) together with @opis/json-schema for validation at runtime. So a big thanks to everyone involved in this great project!

Currently, I'm trying to figure out if/how generated DTO-like classes could replace our array shapes with the help of advanced hydration/normalization techniques as provided by i.e. @CuyZ/Valinor. Thats actually why I discovered the unexpected behavior for generic class constructors having optional arguments: https://phpstan.org/r/1e4a2a1d-2beb-46d8-809c-6fdc631efd33.

Activity

  1. added this to the Easy fixes milestone on Jan 19, 2025
  2. phpstan-bot commented on Mar 8, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5079

  3. added 2 commits that reference this issue on Mar 8, 2026
    2913caa
    869ddb3
  4. github-actions commented on Apr 9, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  5. locked as resolved and limited conversation to collaborators on Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions