Reputation: 40861
What is the correct syntax to document an array of mixed strings and ints?
public function toArray(): array
{
return [
'string',
42,
];
}
Here are the options I've considered:
/**
* @return string|int[]
*/
But this seems to indicate it would either be a string
or an int[]
/**
* @return string[]|int[]
*/
And this would seem to indicate either an array of strings or an array of ints.
Upvotes: 2
Views: 2083
Reputation: 645
Have a look on this document
at the last last bottom of the page
specified containing multiple types, the Type definition informs the reader of the type of each array element. Each element can be of any of the given types.
@return (int|string)[]
Also have a look on return in case needed more details.
Upvotes: 3