Objective
\Drupal\Component\Utility\MapArrayexists to work around a PHP bug witharray_combine().- https://bugs.php.net/bug.php?id=34857 was fixed in PHP 5.4.0.
MapArraycan also be used as a shortcut to combinearray_combine()andarray_map(), although that feature is very rarely used (if at all) in core.
Proposed resolution
- Remove
\Drupal\Component\Utility\MapArrayand replace all usages with array_combine(), and potentially array_map().
API changes
From HEAD: MapArray has been removed.
From D7: drupal_map_assoc() has been removed.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | interdiff.txt | 9.54 KB | ParisLiakos |
| #10 | 2092095-10-remove-MapArray.patch | 62.11 KB | ParisLiakos |
| #6 | 2092095-6-remove-MapArray.patch | 61.05 KB | tstoeckler |
Comments
Comment #1
sunCorrection:
https://bugs.php.net/bug.php?id=34857 was fixed around the time of PHP 5.1, but is only available since PHP 5.4:
http://php.net/manual/en/function.array-combine.php#refsect1-function.ar...
So once #2152073: Bump Drupal core's PHP requirement to 5.4.2 is possible and done, we can eliminate
MapArrayentirely.The optional
$callbacksupport is completely obsolete since PHP 5.3 already, because that's the same as:Comment #2
ParisLiakos commentedComment #3
tstoecklerHmm... interesting that's very weird documentation then on the PHP site, because that clearly says "PHP Version: 5.1.0RC1"
Anyway, since I'm assigned to this anyway, taking a stab at this.
Comment #4
tstoecklerHere we go.
Unassigning for now, as this is not exactly very high on my hitlist right now.
Comment #6
tstoecklerOops.
Comment #8
sunComment #9
sunActually, this removes the @deprecated function, too. :)
Comment #10
ParisLiakos commentedwrong order of arguments:)
Comment #11
tstoecklerOh, wow, that was quite stupid. Thanks @ParisLiakos!!
Comment #12
ParisLiakos commentedNo, worries.. messing up order of arguments in PHP is a common fail..php--
Comment #13
sunWow, this looks awesome - great job!
I guess we need to prepare a draft change notice for the API change of removing
drupal_map_assoc(), describing how to achieve the same with native PHP (as demonstrated in this patch).Comment #14
ParisLiakos commenteddraft change record: https://drupal.org/node/2207453
Comment #15
tstoecklerChange record looks great. Added some links to the PHP functions and an example of the Drupal 8 MapArray version.
Comment #16
catchThat PHP bug isn't the reason we have MapArray, this is. Let's see if that's still valid first and whether we care or not.
https://drupal.org/comment/913381#comment-913381
Comment #17
catchIgnore me, I had another issue that got reverted, but the one linked above got in. So yes indeed that's the only reason, and we're on 5.4 now.
Committed/pushed to 8.x, thanks! Nice to see us finally get rid of this after trying six years ago.
Comment #18
MixologicFyi: drupal_map_assoc is used by drush currently, so if you'll have some drush problems with current d8 HEAD until its fixed.