Depreciated preg_match_all()

Created on 7 April 2025, about 1 month ago

Problem/Motivation

I added ECA for the first time and started getting the following error:

Deprecated function: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\eca\Token\ContribToken->scanRootLevelTokens() (line 471 of myserver/modules/contrib/eca/src/Token/TokenDecoratorTrait.php)

Steps to reproduce

I'm using Drupal 10.4.6 and PHP 8.1.32

Thanks for any help! This looks like a great module!

Michael

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wattdesigns

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wattdesigns
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    That's odd. Line 471 of the file src/Token/TokenDecoratorTrait.php contains a comments and nothing that would be in any way related to the message. The code for the method scanRootLevelTokens is at line 420 and gets called from 2 different places elsewhere.

    One of those calls seems to call it with a NULL value instead of a string, which is odd. It could well be any other module that does something with tokens. But we don't know at this point.

    Can you please provide the full stacktrace for this message?

    And also, please provide steps to reproduce the problem, otherwise we have no chance to find the reason for it.

  • πŸ‡ΊπŸ‡ΈUnited States wattdesigns

    Here's what shows up in my error logs stripping out my server info.

    Deprecated function: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\eca\Token\ContribToken->scanRootLevelTokens() (line 471 of SERVERINFO/modules/contrib/eca/src/Token/TokenDecoratorTrait.php)
    #0 SERVERINFO/core/includes/bootstrap.inc(166): _drupal_error_handler_real(8192, 'preg_match_all(...', '/home/SERVERINFO/p...', 471)
    #1 [internal function]: _drupal_error_handler(8192, 'preg_match_all(...', '/home/SERVERINFO/p...', 471)
    #2 SERVERINFO/modules/contrib/eca/src/Token/TokenDecoratorTrait.php(471): preg_match_all('/\n \\[ ...', NULL, NULL)
    #3 SERVERINFO/modules/contrib/eca/src/Token/TokenDecoratorTrait.php(464): Drupal\eca\Token\ContribToken->scanRootLevelTokens(NULL)
    #4 SERVERINFO/modules/menu_token/src/Service/MenuTokenContextManager.php(64): Drupal\eca\Token\ContribToken->scan(NULL)
    #5 SERVERINFO/modules/menu_token/menu_token.module(396): Drupal\menu_token\Service\MenuTokenContextManager->prepareContextualLinks(Array, Array)
    #6 SERVERINFO/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): menu_token_menu_links_discovered_alter(Array, NULL, NULL)
    #7 SERVERINFO/core/lib/Drupal/Core/Menu/MenuLinkManager.php(127): Drupal\Core\Extension\ModuleHandler->alter('menu_links_disc...', Array)
    #8 SERVERINFO/core/lib/Drupal/Core/Menu/MenuLinkManager.php(150): Drupal\Core\Menu\MenuLinkManager->getDefinitions()
    #9 SERVERINFO/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(90): Drupal\Core\Menu\MenuLinkManager->rebuild()
    #10 SERVERINFO/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php(78): Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->menuLinksRebuild()
    #11 [internal function]: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber->onRouterRebuild(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #12 SERVERINFO/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #13 SERVERINFO/core/lib/Drupal/Core/Routing/RouteBuilder.php(197): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Component\EventDispatcher\Event), 'routing.route_f...')
    #14 SERVERINFO/core/lib/Drupal/Core/Routing/RouteBuilder.php(210): Drupal\Core\Routing\RouteBuilder->rebuild()
    #15 SERVERINFO/core/lib/Drupal/Core/Routing/RouteBuilder.php(222): Drupal\Core\Routing\RouteBuilder->rebuildIfNeeded()
    #16 SERVERINFO/core/lib/Drupal/Core/DrupalKernel.php(723): Drupal\Core\Routing\RouteBuilder->destruct()
    #17 SERVERINFO/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\LocalRedirectResponse))
    #18 {main}

  • πŸ‡ΊπŸ‡ΈUnited States wattdesigns

    As for Token modules, I have the following enabled.

    menu_token Version: 9.1.0-alpha1+7-dev
    realname Version: 2.0.0 (requires Token)
    token Version: 8.x-1.15
    rules_token Version: 2.0.1

    As I'm attempting to use ECA from now on, let me disable the rules_token module and see if that changes things.

    Uninstalled rules_token and still have the error.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    From the stack trace, this comes from menu_token/src/Service/MenuTokenContextManager.php. So they must test for something that is a NULL, which is what they shouldn't do. The token methods require strings, not NULLs. In the past, that didn't matter, but nowadays, PHP has become stricter about argument types.

    But still, the line numbers in the stacktrace don't match up with the real code of ECA, so I wonder what's going on there. This question is unrelated, though.

  • πŸ‡ΊπŸ‡ΈUnited States wattdesigns

    Ah HA! Thank you so much! Wonder why it started sending the error once ECA was installed? I've used menu_token for months with no error and I didn't update my php or anything either. Weird! I'll head down that path with them.

    Thanks for your detective work!

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    That's because ECA decorates the token service and uses the preg_match_all from PHP in there. And that method complains about the NULL value.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
  • πŸ‡ΊπŸ‡ΈUnited States wattdesigns

    Thank you again! I should have said this ages ago, but I took my issue to the menu_token people. You can feel free to close this issue as I'm fairly sure my issue isn't with ECA.

    Thanks!

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thank you.

Production build 0.71.5 2024