Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293485

Allow NestedArray::mergeDeepArray() to preserve integer keys

$
0
0

Problem/Motivation

Configuration files make use of keys such as "404". When ingesting these values into an array PHP will automatically cast these keys to integer types. The default behaviour of NestedArray::mergeDeepArray(), which is used to merge new and overridden data into a Config object, causes the following result:

thingies:
  0: Apples
  1: Bananas
  404: 404-page
  herp: derp
more thingies:
  0: Apples
  1: Bananas
  404: new-page
  herp: derp
result:
  0: Apples
  1: Bananas
  2: Apples
  3: Bananas
  4: 404-page
  5: new-pag
  herp: derp
desired result:
  0: Apples
  1: Bananas
  404: new-page
  herp: derp

Proposed resolution

  • Add a new parameter to NestedArray::mergeDeepArray() which will cause integer keys to be preserved.
  • Add a new method onto the Config class to facilitate merging in data correctly
  • Update override methods in the Config class to use mergeDeepArray(x, TRUE)
  • Add tests for the upgrade path and overridden data that use integer keys

Remaining tasks

None.

User interface changes

None.

API changes

  • NestedArray::mergeDeepArray() accepts a second parameter to allow the preservation of integer keys, set to FALSE by default.
  • Config class has a new merge($data) method.

Original report by @justafish

Following on from an issue shown in #1824762: Convert admin_compact_mode to CMI mergeDeepArray() does not preserve integer keys similarly to array_merge_recursive, which is causing issues when merging config objects that contain numeric keys.

The attached patch adds the ability to preserve keys.

---
Updated as far as #25


Viewing all articles
Browse latest Browse all 293485

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>