You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @return array<int, int|string> The keys/indices of the collection, in the order of the corresponding
* elements in the collection.
*
* @psalm-return TKey[]
*/
publicfunctiongetKeys() : array;
/**
* Gets all values of the collection.
*
* @return array The values of all elements in the collection, in the order they
* appear in the collection.
*
* @psalm-return T[]
*/
publicfunctiongetValues() : array;
The above specifies that those method return T[]. However, ArrayCollection actually returns list<T> (see documentation on list type). Is it unintentional, or are implementations actually allowed to return sparse arrays from those methods?
The text was updated successfully, but these errors were encountered:
@drupol they are not equivalent. list implies that indices go from 0 to count($list) - 1 with the step 1 (0, 1, 2, 3 ... $count -1) with no gaps and shuffling. In array there might be gaps and any order.
Example: [ 0 => 'zero', 2 => 2 ] is a valid array<int, int|string>, but invalid list<int|string> [ 0 => 'zero', 1 => 1 ] is both a valid array<int, int|string> and list<int|string>
There is indeed nothing "wrong" in existing annotations, but list would be more precise and therefore is better - because the retval of these methods could be used as arguments to functions type-hinted against list.
collections/lib/Doctrine/Common/Collections/Collection.php
Lines 118 to 136 in a4504c7
The above specifies that those method return
T[]
. However,ArrayCollection
actually returnslist<T>
(see documentation on list type). Is it unintentional, or are implementations actually allowed to return sparse arrays from those methods?The text was updated successfully, but these errors were encountered: