Page MenuHomePhabricator

Deprecate array_merge_recursive merge strategy from extension.json's "config" section
Open, Needs TriagePublic

Description

As noted in the extension.json documentation and demonstrated at T283464#7106236, the array_merge_recursive merge strategy is not intuitive and not recommended. In fact, it does not appear to be used in any of the extensions or skins that codesearch is aware of.

The array_replace_recursive merge strategy is likely more useful, although also seldom used.

To prevent confusion and accidental use of array_merge_recursive when the behavior of array_replace_recursive is likely desired, the array_merge_recursive merge strategy should be removed.

Event Timeline

array_merge_recursive is used in core as the default merge strategy for $wgHooks and $wgPasswordPolicy. Is array_merge_recursive the correct behavior in those cases? If so, this task should be declined.

Meh. Yes, that's a problem. For $wgHooks, array_merge_recursive is indeed what we want.

1<?php
2
3$wgHooks1 = [
4 'Foo' => [
5 'X::onFoo',
6 'Y::onFoo',
7 [ 'myFoo', [ 'n' => 1, 'm' => 2, 3 ] ]
8 ],
9 'Bar' => [
10 'X::onBar',
11 'Y::onBar',
12 [ 'myBar', [ 'n' => 11, 'm' => 12, 13 ] ]
13 ],
14];
15
16$wgHooks2 = [
17 'Foo' => [
18 'A::onFoo',
19 'B::onFoo',
20 [ 'yourFoo', [ 'n' => 1, 'm' => 2, 3 ] ]
21 ],
22 'Bar' => [
23 'A::onBar',
24 'B::onBar',
25 [ 'yourBar', [ 'n' => 21, 'm' => 22, 23 ] ]
26 ],
27];
28
29print "\n\narray_merge:\n";
30var_export( array_merge( $wgHooks1, $wgHooks2 ) );
31
32print "\n\narray_merge_recursive:\n";
33var_export( array_merge_recursive( $wgHooks1, $wgHooks2 ) );
34
35print "\n\narray_replace_recursive:\n";
36var_export( array_replace_recursive( $wgHooks1, $wgHooks2 ) );

Legoktm subscribed.

If this is not being used in any extension.json/skin.json files we can certainly deprecate it for use in extension.json/skin.json "config" blocks while still allowing its use internally for $wgHooks/$wgPasswordPolicy.

Legoktm renamed this task from Remove array_merge_recursive merge strategy to Deprecate array_merge_recursive merge strategy from extension.json's "config" section.Oct 6 2021, 4:12 PM

Change 729998 had a related patch set uploaded (by Cicalese; author: Cicalese):

[mediawiki/core@master] Deprecate array_merge_recursive merge strategy for extension/skins

https://gerrit.wikimedia.org/r/729998

Change 729998 merged by jenkins-bot:

[mediawiki/core@master] Deprecate array_merge_recursive merge strategy for extension/skins

https://gerrit.wikimedia.org/r/729998