Page MenuHomePhabricator

Mailgun, Warning: : array_key_exists() expects parameter 2 to be array, null given in
Open, Needs TriagePublic

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

Addshore created this task.Aug 19 2019, 5:42 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 19 2019, 5:42 PM
Addshore updated the task description. (Show Details)Oct 19 2019, 6:46 PM

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.