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
Comment #2
andypostLooking how to add a test but looks it needs follow-up to remove Request object from class property (needs to be deprecated)
Comment #3
andypostLet's see if something will fail
Comment #4
andypostFix component
Comment #5
longwaveDuplicate of #3328187: PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in docroot/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 112 and #3314489: strpos(): Passing null to parameter in PhpMail though I think this solution is better.
Also I wonder if this code is even used given #2983438: Truncated MailFrom address - Incorrect Windows detection
Comment #7
andypostThank you! Better title
We can't use
DeprecatedServicePropertyTraitas request is not a service and can't use__get()because it makes deprecated property public, so not clear how to provide BCComment #8
longwaveLet's move the fix to #3328187: PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in docroot/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 112 and then figure out how to deprecate the property once it's unused.