From ef09245174d6fd1ec856dc5df65cf07cc4ac8884 Mon Sep 17 00:00:00 2001 From: didix16 Date: Fri, 15 Nov 2019 13:15:55 +0100 Subject: [PATCH] Added access to inner key on map() Closure This enhancement gives to map() Closure the capability to access also the keys of the inner array holding the elements. Until now, we were able to access just the element on map Closure but not the key. So I propose to add the ability to access also the key for do some statements inside the Closure with key related. I have the need to add it since in my project I must get the asociative key to take a decision in function of the current key element and I thought that may be usefull for everyone in some other projects to access the key of current processing element. --- lib/Doctrine/Common/Collections/ArrayCollection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Common/Collections/ArrayCollection.php b/lib/Doctrine/Common/Collections/ArrayCollection.php index 56e1d30e4..2d1ba59e7 100644 --- a/lib/Doctrine/Common/Collections/ArrayCollection.php +++ b/lib/Doctrine/Common/Collections/ArrayCollection.php @@ -325,12 +325,12 @@ public function getIterator() : Traversable * @return static * * @psalm-template U - * @psalm-param Closure(T=):U $func + * @psalm-param Closure(T=, TKey=):U $func * @psalm-return static */ public function map(Closure $func) : Collection { - return $this->createFrom(array_map($func, $this->elements)); + return $this->createFrom(array_map($func, $this->elements, array_keys($this->elements))); } /**