Page MenuHomePhabricator

array union operator `+=` does not work as intended
Closed, ResolvedPublic

Description

The PHP array union operator += does not work as intended in [[https://phabricator.wikimedia.org/diffusion/EARU/browse/master/src/UserNameSessionProvider.php|src/UserNameSessionProvider]] on lines 459 and 571, because it it used on non associative arrays.

Both arrays will be changed to associative arrays first before the operator is getting applied. But then the compared keys are integer indices, and they exist in both arrays.

Instead of the union operator += the functions array_merge and array_unique have to be used on non associative arrays.

Related Objects

Event Timeline

Enst80 renamed this task from array operator `+=` does not work as intended to array union operator `+=` does not work as intended.Feb 25 2018, 12:11 AM
Enst80 updated the task description. (Show Details)
Enst80 updated the task description. (Show Details)
Enst80 updated the task description. (Show Details)

Another option is to use the Special Page name as the array key and boolean true as the value. That would allow the use of the union operator without incurring duplicates. The foreach would need to be modified to match:

foreach ( $disableSpecialPages as $page => $disable )

Change 421662 had a related patch set uploaded (by Enst80; owner: Enst80):
[mediawiki/extensions/Auth_remoteuser@master] Redone array union operations

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

@jrchamp : Tried it with your suggestion of using a $disable value, but that looked more complicated than the current patch set and its use of the array_push() function.

@Enst80 Understood. I uploaded a new patch set to provide an example of how it might be simpler. I hope you like it!

Change 421662 merged by jenkins-bot:
[mediawiki/extensions/Auth_remoteuser@master] Fully embrace associative arrays

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

Change 423332 had a related patch set uploaded (by Enst80; owner: Enst80):
[mediawiki/extensions/Auth_remoteuser@REL1_27] Fully embrace associative arrays

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

Change 423333 had a related patch set uploaded (by Enst80; owner: Enst80):
[mediawiki/extensions/Auth_remoteuser@REL1_28] Fully embrace associative arrays

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

Change 423334 had a related patch set uploaded (by Enst80; owner: Enst80):
[mediawiki/extensions/Auth_remoteuser@REL1_29] Fully embrace associative arrays

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

Change 423335 had a related patch set uploaded (by Enst80; owner: Enst80):
[mediawiki/extensions/Auth_remoteuser@REL1_30] Fully embrace associative arrays

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

Change 423332 merged by jenkins-bot:
[mediawiki/extensions/Auth_remoteuser@REL1_27] Fully embrace associative arrays

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

Change 423333 merged by jenkins-bot:
[mediawiki/extensions/Auth_remoteuser@REL1_28] Fully embrace associative arrays

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

Change 423334 merged by jenkins-bot:
[mediawiki/extensions/Auth_remoteuser@REL1_29] Fully embrace associative arrays

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

Change 423335 merged by jenkins-bot:
[mediawiki/extensions/Auth_remoteuser@REL1_30] Fully embrace associative arrays

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

Backporting done.