Call to a member function toArray() on false in Drupal\smart_date_recur\Plugin\QueueWorker\RecurRuleUpdate->processItem()

Created on 2 September 2025, about 1 month ago

Problem/Motivation

The fix from two years ago in https://www.drupal.org/project/smart_date/issues/3399016 πŸ› Call to a member function toArray() on bool in Drupal\smart_date_recur\Plugin\QueueWorker\RecurRuleUpdate->processItem() Fixed does not work as advertised with PHP 8.3. The fix was to just add a question mark after the variable that might not be defined, before calling toArray() on it:
$new_instances = $rule->getNewInstances()?->toArray();
Given a null value, in PHP 8.3 that only silences the error and not the warning. But given a boolean value (which was the originally reported error condition) it still returns an error.

Steps to reproduce

At the PHP prompt, you can see

> $foo->toArray()
   WARNING  Undefined variable $foo.
   Error  Call to a member function toArray() on null.

> $foo?->toArray()
   WARNING  Undefined variable $foo.
= null

> $foo = false
= false

> $foo?->toArray()
   Error  Call to a member function toArray() on false.

Since false is one of getNewInstances()' documented return values, we should be prepared to handle that condition.

Proposed resolution

$new_instances = $rule->getNewInstances();
if (!$new_instances) {
  // No need to process this rule.
  unset($rules[$rrid]);
  continue;
}
$new_instances = $new_instances->toArray();

Remaining tasks

make a MR

πŸ› Bug report
Status

Active

Version

4.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024