Skip to content

Array type transitions from array{} to *NEVER* to mixed with array assignments #12931

@ryanhughes

Description

@ryanhughes

Bug report

When assigning values to a nested array within a typed array, since 2.1.12 the nested array type transitions from array{} to *NEVER* to mixed as values are assigned and then reports an offsetAccess.nonOffsetAccessible error.

The issue appears to be triggered by the type annotation on the parent array @var array<string, mixed>, removing the annotation makes the issue disappear.

Code snippet that reproduces the problem

https://phpstan.org/r/2894f0cc-6c77-48bf-952c-5aa5677c6913

Expected output

  • PHPStan should maintain the array type information through the assignments
  • The type should be something like array<string, int> after the assignments
  • Subsequent array access should be valid

Actual behaviour

  1. Initial empty array is correctly typed as array{}
  2. After first assignment, type becomes *NEVER*
  3. After second assignment, type becomes mixed

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

Yes, it catches refactoring errors all time I couldn't ship as safely without it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions