Deprecated functions after the PHP upgrade to 8.1

Created on 14 September 2022, over 2 years ago
Updated 22 March 2023, over 1 year ago

Problem/Motivation

Deprecated functions after the PHP upgrade to 8.1.
Deprecated function: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\typed_data\PlaceholderResolver->scan() (line 185 of /modules/contrib/typed_data/src/PlaceholderResolver.php)

Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\typed_data\PlaceholderResolver->replacePlaceHolders() (line 172 of /modules/contrib/typed_data/src/PlaceholderResolver.php)

🐛 Bug report
Status

Active

Version

3.0

Component

Rules Core

Created by

🇪🇪Estonia mikkmiggur

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Using: 8.x-3.x-dev, 9.5, and php 8.1.

    Deprecated function: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\typed_data\PlaceholderResolver->scan() (line 185 of modules/contrib/typed_data/src/PlaceholderResolver.php).
    Drupal\typed_data\PlaceholderResolver->scan(NULL) (Line: 53)
    Drupal\typed_data\PlaceholderResolver->resolvePlaceholders(NULL, Array, NULL, Array) (Line: 167)
    Drupal\typed_data\PlaceholderResolver->replacePlaceHolders(NULL, Array) (Line: 72)
    Drupal\rules\Plugin\RulesDataProcessor\TokenProcessor->process(NULL, Object) (Line: 320)
    Drupal\rules\Plugin\RulesExpression\ActionExpression->processValue(NULL, Array, Object) (Line: 297)
    Drupal\rules\Plugin\RulesExpression\ActionExpression->processData(Object, Object) (Line: 83)

    And

    Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\typed_data\PlaceholderResolver->replacePlaceHolders() (line 172 of modules/contrib/typed_data/src/PlaceholderResolver.php).
    Drupal\typed_data\PlaceholderResolver->replacePlaceHolders(NULL, Array) (Line: 72)
    Drupal\rules\Plugin\RulesDataProcessor\TokenProcessor->process(NULL, Object) (Line: 320)
    Drupal\rules\Plugin\RulesExpression\ActionExpression->processValue(NULL, Array, Object) (Line: 297)
    Drupal\rules\Plugin\RulesExpression\ActionExpression->processData(Object, Object) (Line: 83)

    I had same deprecation messages for a rule that sent an email after a comment was submitted. The patch works for me clear the errors.

  • 🇧🇪Belgium f2boot

    Patch #5 breaks Data Comparison if value = 0 so let's check if value is a string before going for return

  • 🇧🇪Belgium f2boot

    Sorry, got a bit too enthousiast.
    Here is a new try, limiting "return" in patch #5 to empty string

  • 🇺🇸United States scotthreha

    Drupal 9.5.8
    PHP 8.1.19
    Rules 8.x-3.x-dev

    I updated to the 8.x-3.x-dev version as suggested, which fixed the deprecated function errors but now none of my rules work as before. I tried deleting and recreating them, still not working. Anyone else have this experience? Any suggestions for how to get Rules working again?

  • 🇩🇪Germany florianboehme

    same here... after updating to Rules 8.x-3.x-dev all deprecated errors are gone, but no rule seems to work anymore. No error appear when the rule should fire.
    I have as trigger on creating/updating user entity – but I don't think it matters.

  • 🇬🇧United Kingdom freelylw

    I have an issue my rules action can't send email out by using the token [node:author:mail], but it works if I use a fixed email address like abc@gmail.com. I got the similar log message like above. please see this post 🐛 Can't send email out by using token [node:author:mail] Active

  • Status changed to Needs review 11 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 11 months ago
    414 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 11 months ago
    414 pass
  • 🇺🇸United States dcam

    Those who are having trouble with rules not firing should make certain they aren't affected by 🐛 Rules registers no listeners on rare occasions. Needs review - basically just clear the cache.

    Setting the issue status to start the tests on #12.

  • 🇯🇲Jamaica axle_foley00

    I had this same issue and the patch in #12 worked for me.

  • 🇺🇸United States tr Cascadia
  • 🇺🇸United States tr Cascadia
  • 🇺🇸United States tr Cascadia

    The root problem is that there are cases when a data processor plugin is being called on to process a NULL value.

    Yes, patches like #12 can narrowly avoid the problem by checking on the value inside the data processor, but as data processors are plugins that means that each and every data processor needs to know it has to do this, then needs to do it. That is not a scalable solution, and it is error prone.

    I better solution IMO is outlined in my comment at #3095216-4: [meta] Data Processors .

    Specifically, DataProcessor plugins should have mandatory method defined in the plugin interface to declare the data type(s) they can process. That way, we can see if the DataProcessor applies to our data before we try to process our data. That's far better than just checking for NULL, because as described in the related issue #2849810: Data processors do not check type before performing type-specific operations the problem isn't always a NULL value - however it IS always a value of the wrong data type.

  • 🇨🇦Canada sagesolutions

    I upgraded to Drupal 10.3 and updated rules to 4.0-dev and ran into this issue.

    I had a slightly different error, but the patch #12 still fixed it

    TypeError: Drupal\typed_data\PlaceholderResolver::scan(): Argument #1 ($text) must be of type string, null given, called in /web/modules/contrib/rules/src/Plugin/RulesDataProcessor/TokenProcessor.php on line 69 in Drupal\typed_data\PlaceholderResolver->scan() (line 180 of /web/modules/contrib/typed_data/src/PlaceholderResolver.php).

  • 🇮🇳India ravis

    I am using Rules 4.0-dev on a Drupal 10.3 installation with PHP 8.2

    I applied patch #12 by @f2boot
    But, I git this error message in my PHP log.

    Uncaught PHP Exception TypeError: "rules_help(): Return value must be of type string, null returned" at testsite\web\modules\contrib\rules\rules.module line 48
    

    This patch fixed this error and Rules module is working.

  • 🇮🇳India ravis

    This is the patch I applied in addition to patch #12

Production build 0.71.5 2024