Skip to content

Fix EmailTask named-parameter error for associative address arrays#472

Merged
dereuromark merged 2 commits intomasterfrom
fix/email-task-associative-addresses
Apr 17, 2026
Merged

Fix EmailTask named-parameter error for associative address arrays#472
dereuromark merged 2 commits intomasterfrom
fix/email-task-associative-addresses

Conversation

@dereuromark
Copy link
Copy Markdown
Owner

Summary

Fixes #471.

EmailTask::run() expanded every mailer setting through call_user_func_array(). Under PHP 8+, string keys in the argument array are interpreted as named parameters, so queued payloads using CakePHP's associative address-map format:

'to' => ['recipient@example.com' => 'Recipient Name']

...failed with Unknown named parameter $recipient@example.com against setTo()/setFrom()/etc.

Fix

Address setters (to, from, cc, bcc, replyTo, plus sender/returnPath) are now handled explicitly before the generic settings loop, consistent with how theme/template/attachments were already special-cased.

A small addressArguments() helper normalizes the value:

  • list-shaped arrays (e.g. ['email', 'Name'] or legacy wrapped [['email' => 'Name']]) are unpacked positionally — matching the previous behavior,
  • any other shape, including associative email => name maps, is forwarded as a single positional argument so PHP's named-parameter semantics never kick in.

All previously working payload formats continue to work unchanged; the associative map format now also works, matching what Cake\Mailer\Mailer::setTo() natively accepts.

A regression test covers to, from, cc, bcc, and replyTo with associative address maps.

PHP 8 treats string keys in the argument array of call_user_func_array()
as named parameters, so queued payloads with an associative email => name
map for to/from/cc/bcc/replyTo would fail with 'Unknown named parameter'.

Route address setters through a helper that unpacks list-shaped values
positionally (preserving the prior behavior) and forwards associative
maps as a single positional argument.
@dereuromark dereuromark added this to the 8.x milestone Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.15%. Comparing base (a534d1f) to head (9e683eb).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #472      +/-   ##
============================================
+ Coverage     77.08%   77.15%   +0.07%     
- Complexity      938      944       +6     
============================================
  Files            45       45              
  Lines          3172     3182      +10     
============================================
+ Hits           2445     2455      +10     
  Misses          727      727              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark dereuromark merged commit 6eda87a into master Apr 17, 2026
16 checks passed
@dereuromark dereuromark deleted the fix/email-task-associative-addresses branch April 17, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown named parameter in EmailTask

2 participants