Problem/Motivation

Another PHP 8.5 "Using null as an array offset is deprecated" deprecation warning catched in src/Plugin/search_api/processor/ReverseEntityReferences.php.

Deprecated function: Using null as an array offset is deprecated, use an empty string instead i Drupal\search_api\Plugin\search_api\processor\ReverseEntityReferences->addFieldValues() (line 299 of /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/search_api/processor/ReverseEntityReferences.php) #0 /app/platform_drupal_11_4_x/core/includes/bootstrap.inc(104): _drupal_error_handler_real()
      #1 /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/search_api/processor/ReverseEntityReferences.php(299): _drupal_error_handler()
      #2 /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/views/field/SearchApiFieldTrait.php(876): Drupal\search_api\Plugin\search_api\processor\ReverseEntityReferences->addFieldValues()
      #3 /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/views/field/SearchApiFieldTrait.php(760): Drupal\search_api\Plugin\views\field\SearchApiEntityField->extractProcessorProperty()
      #4 /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/views/field/SearchApiFieldTrait.php(542): Drupal\search_api\Plugin\views\field\SearchApiEntityField->getValuesToExtract()
      #5 /app/platform_drupal_11_4_x/modules/contrib/search_api/src/Plugin/views/field/SearchApiEntityField.php(274): Drupal\search_api\Plugin\views\field\SearchApiEntityField->traitPreRender()

Steps to reproduce

- Install Drupal 11.4.5
- Install Search API 1.4.1
- Setup ReverseEntityReferences processor on a search index.
- Observe the warning in the message box, or in dblog.

Proposed resolution

Remaining tasks

Issue fork search_api-3620432

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

flemming.fridthjof created an issue. See original summary.

andres alvarez made their first commit to this issue’s fork.

andres alvarez’s picture

Confirmed the root cause. In ReverseEntityReferences::addFieldValues() (src/Plugin/search_api/processor/ReverseEntityReferences.php:299), $to_extract[$property_name][$nested][] = $field; uses $nested directly as an array key, where $nested comes from Utility::splitPropertyPath($property_path, FALSE). That function returns NULL for the second element whenever the property path has no : separator, which is exactly the case for this processor's own reverse-reference property. A few lines further down, the same method already expects an empty-string key for this case (isset($fields_to_extract[''])), so this only worked previously through PHP's implicit NULL-to-empty-string array key coercion — precisely the behavior PHP 8.5 now deprecates.

Fix: change line 299 to $to_extract[$property_name][$nested ?? ''][] = $field;, making the existing expectation explicit instead of relying on the deprecated coercion. No other logic changed.

Added a Kernel test (testAddFieldValuesWithoutNestedProperty) exercising the no-nested-property code path, which the existing test suite didn't cover (the existing test's property path includes a nested sub-property and never hits this branch). Verified on real PHP 8.5 that reverting the source fix (keeping the new test) reproduces the exact reported deprecation, "Using null as an array offset is deprecated, use an empty string instead", and that restoring the fix removes it while all assertions continue to pass.

MR to follow.

andres alvarez’s picture

Status: Active » Needs review

bserem made their first commit to this issue’s fork.

bserem’s picture

merge request !373 addresses more areas and also fixes the code quality finding on !357