Problem/Motivation

Running drush to send mail I see deprecation in logs because SERVER_SOFTWARE environment variable is not set.

Steps to reproduce

run drush to execute job to send mail and then check logs

Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\Mail\Plugin\Mail\PhpMail->mail() (line 114 of /var/www/html/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php)

#0 /var/www/html/web/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /var/www/html/web/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php(114): str_contains()
#3 /var/www/html/web/core/lib/Drupal/Core/Mail/MailManager.php(307): Drupal\Core\Mail\Plugin\Mail\PhpMail->mail()
#4 /var/www/html/web/core/lib/Drupal/Core/Mail/MailManager.php(180): Drupal\Core\Mail\MailManager->doMail()
#5 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(583): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
#6 /var/www/html/web/core/lib/Drupal/Core/Mail/MailManager.php(179): Drupal\Core\Render\Renderer->executeInRenderContext()
#7 /var/www/html/web/core/modules/update/update.fetch.inc(44): Drupal\Core\Mail\MailManager->mail()
#8 /var/www/html/web/core/modules/update/update.module(193): _update_cron_notify()
#9 /var/www/html/web/core/lib/Drupal/Core/Cron.php(335): update_cron()
#10 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Cron->Drupal\Core\{closure}()
#11 /var/www/html/web/core/lib/Drupal/Core/Cron.php(318): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#12 /var/www/html/web/core/lib/Drupal/Core/Cron.php(159): Drupal\Core\Cron->invokeCronHandlers()
#13 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#14 /var/www/html/web/core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php(65): Drupal\Core\ProxyClass\Cron->run()
#15 [internal function]: Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate()
#16 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
#17 /var/www/html/web/vendor/symfony/http-kernel/HttpKernel.php(100): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate()
#19 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate()
#20 /var/www/html/web/vendor/drush/drush/src/Boot/DrupalBoot8.php(331): Drupal\Core\DrupalKernel->terminate()
#21 [internal function]: Drush\Boot\DrupalBoot8->terminate()
#22 {main}

Proposed resolution

The check should detect Windows, so better to replace it with PHP_OS which is used for such places in core

Remaining tasks

patch, review, commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
StatusFileSize
new806 bytes

Looking how to add a test but looks it needs follow-up to remove Request object from class property (needs to be deprecated)

andypost’s picture

StatusFileSize
new689 bytes
new1.2 KB

Let's see if something will fail

andypost’s picture

Component: base system » mail system

Fix component

Status: Needs review » Needs work

The last submitted patch, 3: 3372667-3.patch, failed testing. View results

andypost’s picture

Title: PhpMail::mail() should not throw deprecation » Deprecate PHPMail::request property
Status: Needs work » Needs review
StatusFileSize
new1.19 KB
new2.4 KB

Thank you! Better title

We can't use DeprecatedServicePropertyTrait as request is not a service and can't use __get() because it makes deprecated property public, so not clear how to provide BC

longwave’s picture

Category: Bug report » Task
Status: Needs review » Postponed

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.