Page MenuHomePhabricator

Mailgun, Warning: : array_key_exists() expects parameter 2 to be array, null given in
Closed, ResolvedPublic

Description

Warning: : array_key_exists() expects parameter 2 to be array, null given in
/var/www/html/extensions/Mailgun/vendor/mailgun/mailgun-php/src/Mailgun/Messages/BatchMessage.php on line 87

Using the release tagged as REL1_31 and REL1_33

This occurred while requesting an email be sent for email address verification.

Event Timeline

Hmm, the problem seems to be (also) in the Mailgun library. L067 in the Mailgun extension uses:

$message->addToRecipient( $recip );

from BatchMessage.php, which extends MessageBuilder.php. The method signature and doc block states, that the second parameter, $variables, is either an array or null:

@param array|null $variables

Internally the method uses MessageBuilder::addRecipient and passes the variables to it as well. However, this method now magically changes the expected value to be a string (neither null, nor array is an accepted value):

@param string $address

Even more, the BatchMessage.php (which is used in the extension) states, that only an array is accepted at all:

@param array $variables

This code is then also the point in the code which triggers the warning, as the method is expecting an array and uses it as an array, while the actual value is always null.

So, two possible solutions:

  • Simply pass an empty array as a second parameter in the Mailgun extension
  • Fix this implausible code in the mailgun library

For the first solution, I'll create a task in Google-Code-in-2019 :)

Or, even better, just update the mailgun-php library, if possible, the problem should be fixed there already :D

Change 561244 had a related patch set uploaded (by BrandonXLF; owner: BrandonXLF):
[mediawiki/extensions/Mailgun@master] Pass empty array to addToRecipient

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

Change 561244 merged by jenkins-bot:
[mediawiki/extensions/Mailgun@master] Pass empty array to addToRecipient

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

For the first solution, I'll create a task in Google-Code-in-2019 :)

Hi @Florian, I think we can consider this task resolved and close it, since the immediate problem is no longer there; code merged, GCI task approved. New task should be opened for the other approaches.

Aklapper added a subscriber: BrandonXLF.

Removing task assignee due to inactivity, as this open task has been assigned for more than two years. See the email sent to the task assignee on February 06th 2022 (and T295729).

Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome.

If this task has been resolved in the meantime, or should not be worked on ("declined"), please update its task status via "Add Action… 🡒 Change Status".

Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator.

Aklapper assigned this task to BrandonXLF.

Closing per previous comments