Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Split off from #1279226: jQuery and Drupal JavaScript libraries and settings are output even when no JS is added to the page
drupal_array_merge_deep_array doesn't check if $array is an array before using it inside a foreach
Comment | File | Size | Author |
---|---|---|---|
#1 | i1554142.patch | 1.68 KB | attiks |
Comments
Comment #1
attiks CreditAttribution: attiks commentedComment #2
nod_Looks rtbc to me. Since it's the base system I'm not rtbc it without another review :)
Comment #3
tim.plunkettWhen and why would this be called on something that isn't an array?
I would think this is won't fix, or even add type hinting to the function signature to force it to blow up.
Comment #4
attiks CreditAttribution: attiks commentedI ran into this while making a patch for #1279226: jQuery and Drupal JavaScript libraries and settings are output even when no JS is added to the page and it was blowing up on some tests, that's why I added it. The calling function passes an array, but one of the elements of the array wasn't an array itself, so it failed on the second foreach (
foreach ($array as $key => $value) {
).Comment #5
sunre #4: You likely wanted to use drupal_array_merge_deep() (without last _array suffix).
Type-hinting won't help here.
This function is called relatively often on big arrays and is slow enough already (is_array() is slow) and only exists because PHP's native array_merge_recursive() doesn't allow for a flag that would change its merge behavior for nested string keys.