PHP 8.1 Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated

Created on 21 July 2022, almost 2 years ago
Updated 2 February 2024, 5 months ago

Problem/Motivation

When using a variable of type "View result variable" and the arguments field is empty, it shows the following warning when executing the routine:

Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\business_rules\Plugin\BusinessRulesVariable\ViewResultVariable->evaluate() (line 223 of modules/contrib/business_rules/src/Plugin/BusinessRulesVariable/ViewResultVariable.php).
Drupal\business_rules\Plugin\BusinessRulesVariable\ViewResultVariable->evaluate(Object, Object) (Line: 94)
Drupal\business_rules\Entity\Variable->evaluate(Object) (Line: 708)
Drupal\business_rules\Util\BusinessRulesProcessor->evaluateVariable(Object, Object) (Line: 673)
Drupal\business_rules\Util\BusinessRulesProcessor->evaluateVariables(Object, Object) (Line: 501)
Drupal\business_rules\Util\BusinessRulesProcessor->executeAction(Object, Object) (Line: 344)
Drupal\business_rules\Util\BusinessRulesProcessor->processItems(Array, Object, 'alertas_compara_valores') (Line: 384)
Drupal\business_rules\Util\BusinessRulesProcessor->processItems(Array, Object, 'alertas_envio_p1') (Line: 289)
Drupal\business_rules\Util\BusinessRulesProcessor->processTriggeredRules(Array, Object) (Line: 198)
Drupal\business_rules\Util\BusinessRulesProcessor->process(Object) (Line: 207)
Drupal\business_rules\EventSubscriber\BusinessRulesListener->process(Object, 'business_rules.cron_runs', Object)
...

Steps to reproduce

  1. Create a variable of type "View result variable" and configure it, leaving the arguments field empty.
  2. Create a routine that uses the variable created earlier.
  3. Run the routine created earlier.

Proposed resolution

If the result of the arguments is null, apply an empty string. Line to change.

    // Get settings.
    $defined_view    = $variable->getSettings('view');
    $view_fields     = $variable->getSettings('view_html');
    $args            = $variable->getSettings('arguments');
    $event_variables = $event->getArgument('variables');

to

    // Get settings.
    $defined_view    = $variable->getSettings('view');
    $view_fields     = $variable->getSettings('view_html');
    $args            = $variable->getSettings('arguments') ?? "";
    $event_variables = $event->getArgument('variables');

Remaining tasks

Validate the proposed fix.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal lolgm

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.

Production build 0.69.0 2024