Problem/Motivation

After upgrade to PHP 8.1 debug log reported as below:

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\styleguide\Theme\StyleguideThemeNegotiator->applies() (line 60 of /var/www/html/modules/contrib/styleguide/src/Theme/StyleguideThemeNegotiator.php)

#0 /var/www/html/core/includes/bootstrap.inc(346): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /var/www/html/modules/contrib/styleguide/src/Theme/StyleguideThemeNegotiator.php(60): strpos()
#3 /var/www/html/core/lib/Drupal/Core/Theme/ThemeNegotiator.php(67): Drupal\styleguide\Theme\StyleguideThemeNegotiator->applies()
#4 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(405): Drupal\Core\Theme\ThemeNegotiator->determineActiveTheme()
#5 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(96): Drupal\Core\Theme\ThemeManager->initTheme()
#6 /var/www/html/core/modules/block/src/BlockRepository.php(56): Drupal\Core\Theme\ThemeManager->getActiveTheme()
#7 /var/www/html/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php(137): Drupal\block\BlockRepository->getVisibleBlocksPerRegion()
#8 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(274): Drupal\block\Plugin\DisplayVariant\BlockPageVariant->build()
#9 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
#10 /var/www/html/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#11 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#12 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#13 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#14 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#15 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#16 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#17 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#18 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#19 /var/www/html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#20 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#21 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#22 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#23 /var/www/html/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php(166): Stack\StackedHttpKernel->handle()
#24 /var/www/html/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php(119): Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber->makeSubrequest()
#25 /var/www/html/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php(81): Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber->makeSubrequestToCustomPath()
#26 /var/www/html/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php(109): Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber->on404()
#27 [internal function]: Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase->onException()
#28 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#29 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(219): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#30 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel->handleThrowable()
#31 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#32 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#33 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#34 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#35 /var/www/html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#36 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#37 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#38 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#39 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#40 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#41 {main}

Steps to reproduce

Upgrade to PHP 8.1

Proposed resolution

Similar as https://www.drupal.org/project/advagg/issues/3258389, explicitly casting the argument since null will return an empty string.

Issue fork styleguide-3258816

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hswong3i created an issue. See original summary.

malcomio’s picture

Status: Needs review » Reviewed & tested by the community

The change looks good to me, and seems to fix the issue.

rajab natshah’s picture

Title: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 » Fix [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1
Issue tags: +PHP8.1

MR #5 is working plain diff
Thank you

liam morland’s picture

Issue tags: -PHP8.1
jwilson3’s picture

RTBC++ Any chance of a minor release to get this out?

edmund.dunn’s picture

StatusFileSize
new973 bytes

Adding patch file to keep it immutable. This is just the patch file of @hswong3j work.

hitchshock’s picture

StatusFileSize
new589 bytes

Made the same patch for 8.x-1.x

chrisolof’s picture

MR5 is working. Thanks for the immutable patch!

  • hswong3i committed cd09f1e on 2.x
    Issue #3258816: [PHP 8.1] Deprecated function: strpos(): Passing null to...
oleksiy’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.