Problem/Motivation

In PHP 8.2, dynamic properties are deprecated. At least one class in Search API does not declare all the properties that can be created on its instances.

I've tested this on a site with the latest PHP 8.2 updates/patches for Entity API including #3328049: PHP 8.2 - Fix deprecated dynamic properties, and the messages are still appearing.

Steps to reproduce

  1. Install the latest versions of Search API and its dependencies on a Drupal 7 site running on PHP 8.2. Panopoly distro works for this.
  2. If not using Panopoly, configure a Search API results page.
  3. Create some content and perform a Search API search using keywords in the content.
  4. Note this message in the logs:

Deprecated function: Creation of dynamic property SearchApiQueryFilter::$tags is deprecated in SearchApiQueryFilter->__construct() (line 1022 of /search_api/includes/query.inc).

Proposed resolution

Add the annotation to allow dynamic properties to the class. Another solution would be to declare all the properties in the class.

Remaining tasks

Patch and test.

Comments

cboyden created an issue. See original summary.

cboyden’s picture

Assigned: cboyden » Unassigned
Status: Active » Needs review
StatusFileSize
new388 bytes

Patch is attached.

laryn’s picture

I'm looking at this in the Backdrop version, where a contributor has made the following comment:

> I don't agree with the fix there. It makes more sense to define property $tags, since it's integral to the functioning of the class.

There is a PR on the issue to do so in Backdrop, which could easily be ported here for Drupal 7 if you agree:
https://github.com/backdrop-contrib/search_api/issues/57

drunken monkey’s picture

StatusFileSize
new427 bytes

Thanks a lot for reporting this issue, and especially for already providing a patch!

However, I agree with @argiepiano in the Backdrop PR: We should just declare that property, especially if it’s already set in the constructor.
Patch attached, please test/review!

drunken monkey’s picture

  • drunken monkey committed 1209b0a6 on 7.x-1.x
    Issue #3402005 by drunken monkey, argiepiano, cboyden, laryn: Fixed...
drunken monkey’s picture

Status: Needs review » Fixed

Merged. Thanks again, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.