phpphpstan

Phpstan: how to set array key types?


Is there a way to document an array, where every key is a string and every item is an object of specific types? I tried this

@param array{string, MyObj} $accounts

but apparently Phpstan thinks of it as an array of objects and strings


Solution

  • I think it should look like this:

    /**
     * @param array<string, MyObj> $accounts
     */