Problem/Motivation

Warning: Creating default object from empty value in flexslider_optionset_load() (line 281 of E:\....\sites\all\modules\contrib\flexslider\flexslider.module).

Steps to reproduce

Not sure, currently running PHP 7.4.30, error appears in logs but is non-fatal. Now required to move to PHP 8.x which causes this error to be come fatal for the website.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3329884-4.patch679 bytesdineshkumarbollu

Comments

RBlackman created an issue. See original summary.

RBlackman’s picture

Issue summary: View changes
sgroundwater’s picture

I hit the same error w/ PHP 8.x. I let AI help me with a possible fix. In case it helps others.

---
The error message indicates that the property "options" is being modified on a null value in the function flexslider_optionset_load().

To fix this issue, you can add a null check before attempting to modify the "options" property. Here's an updated version of the code that includes the null check:

/**
 * Fetches the given option set and returns it as an object or NULL if no set could be found.
 */
function flexslider_optionset_load($optionset_name) {
  ctools_include('export');
  $optionset = ctools_export_crud_load('flexslider_optionset', $optionset_name);
  
  if ($optionset !== null) {
    // Ensure the optionset is typecast after being loaded from DB
    _flexslider_typecast_optionset($optionset->options);
  }
  
  return $optionset;
}

In the updated code, we added an if statement to check if $optionset is not null before attempting to modify the "options" property. If $optionset is null, the modification will not be executed.

By including this null check, you can prevent the "Attempt to modify property on null" error.

dineshkumarbollu’s picture

StatusFileSize
new679 bytes

Provided the patch changes suggested in #3, please review