Skip to content

Array does not have offset / Array might not have offset #13862

@JulianAtkins

Description

@JulianAtkins

Bug report

Hey everyone!

Since I upgraded to phpstan v2.1.32 from a much older version (2-3 month old), everything is ok except for a new error that baffles me :(

Parameter #2 $options of function curl_setopt_array expects array{10002: non-empty-string, 78: int, 13: int, 19913: bool, 3: int, 10102: string, 10023: array<int, string>, 10062: non-empty-string, ...}, array{10002: non-falsy-string, 78: 5, 13: 15, 19913: true, 3: int, 10102: 'gzip, deflate', 10023: array{'Accept-Encoding:…'}, 10062?: non-empty-string}|array{10002: non-falsy-string, 78: 5, 13: 15, 19913: true, 3: int, 10102: 'gzip, deflate', 10023: array{'Content-Type:…', 'Accept: application…', 'Accept-Encoding:…', non-falsy-string}, 10062?: non-empty-string, ...} given.
  • Array does not have offset 47.
  • Array might not have offset 10062.

Why does phpstan report errors for optional things that are perfectly valid PHP?

Code snippet that reproduces the problem

https://phpstan.org/r/c2a98325-b76c-43e0-92b0-f0c01016259d

Expected output

No errors with optional array elements.

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

Always a pleasure!!!

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