- Issue created by @BenStallings
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.
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.
$new_instances = $rule->getNewInstances();
if (!$new_instances) {
// No need to process this rule.
unset($rules[$rrid]);
continue;
}
$new_instances = $new_instances->toArray();
make a MR
Active
4.2
Code