User tests: Successful: Unsuccessful:
Pull Request for Issue #42482.
This change addresses a fatal error encountered in the MailerFactory::createMailer
method due to the cloning of a Registry
object containing closures. The proposed fix involves creating a new Registry
instance with the existing $defaultConfiguration
instead of cloning it, effectively preventing the "Serialization of 'Closure' is not allowed" error.
$app = Factory::getApplication();
// Add a closure to the global configuration.
$closure = function() {};
$app->set('closureTest', $closure);
// Attempt to send mail using the MailerFactory.
$mail = Factory::getMailer();
$mail->clearAttachments()->clearAllRecipients();
$mail->sendMail(
(string) $app->get('mailfrom'),
(string) $app->get('fromname'),
'example@example.com',
'A test email subject!',
'A test body.'
);
Attempting to send an email through certain configurations of Joomla 4.x with PHP 8.1 results in a fatal error: "Serialization of 'Closure' is not allowed".
The fatal error is resolved, and emails can be sent successfully without encountering the "Serialization of 'Closure' is not allowed" error.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Mind gone blank - where best to plant that sample code?
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42819.
Apologies, while tidying up the PR, I reordered the test code a bit which meant that the MailerFactory wasn't using the latest application configuration.
$app = Factory::getApplication();
// Add a closure to the global configuration.
$closure = function() {};
$app->set('closureTest', $closure);
// Attempt to send mail using the MailerFactory.
$mail = Factory::getMailer();
$mail->clearAttachments()->clearAllRecipients();
$mail->sendMail(
(string) $app->get('mailfrom'),
(string) $app->get('fromname'),
'example@example.com',
'A test email subject!',
'A test body.'
);
I have just tested again within my template's index.php file and have been able to reproduce the problem with the above code. For testing purposes I put it in the index.php file, but it should have the same results no matter where it's placed as long as it gets executed.
Can we have some tests here?
I have tested this item ✅ successfully on b9c7451
I have tested this item ✅ successfully on b9c7451
I tested with PHP8.3 - error without patch, no error with patch, so I think the test is still valid.
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
bug
Maintainers Checked
PR-4.4-dev
|
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2024-03-04 13:06:09 |
Closed_By | ⇒ | laoneo | |
Labels |
Added:
RTC
|
Thanks!
Mind gone blank - where best to plant that sample code?
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42819.