Skip to content

Array (array<string, string|null>) does not accept key string. #2970

@Kocal

Description

@Kocal

Bug report

I have an array ['html' => null, 'htmlsource' => null, 'txt' => null, 'raw' => null, 'eml' => null] of type array{html: ?string, htmlsource: ?string, txt: ?string, raw: ?string, eml: ?string}.

I'm trying to change $array[$format] value (where $format is either html, htmlsource, txt, raw, or eml), but PHPStan is throwing error Array (array<string, string|null>) does not accept key string..

There is also another error Method Message::getBody() should return string but returns string|null.. I don't know if it's related, but this is super weird since I assign a string to $this->body[$format] if it's equals to null.

Code snippet that reproduces the problem

https://phpstan.org/r/ec4cb784-4886-4bb8-83b8-e034fd042f55

Expected output

The static analytics should not claim the two errors.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions