← Back to context

Comment by bakugo

9 days ago

Type declarations are still quite limited, though. For example, you can declare that a function returns an array or a string, but not an array of strings.

Use a class if you need them.

  • How does that solve the problem? You can't declare an array of strings inside a class, either.

    • You can annotate the method as `@return array<array-key,string>` or even `@return list<string>` (array of strings = indexed via anything that can be used as a key in PHP vs list of strings = indexed via incrementing integers, starting from 0). I guess the OP suggestion was to use Arrayable / Iterable interfaces, which would work as well, but would require more effort (= yes, declare a class)