In PHP 8.2+, the creation of dynamic properties is deprecated

Created on 20 October 2024, 8 days ago

Problem/Motivation

Deprecated dynamic property in TermWeightWidgetOrderProcessor::sortResults() in PHP 8.3

In PHP 8.2+, the creation of dynamic properties is deprecated, and this triggers a deprecation notice in TermWeightWidgetOrderProcessor::sortResults() when the $termWeight property is assigned dynamically to a Result object. This will cause issues in PHP 8.3 and beyond, as dynamic properties are not allowed by default.

The issue occurs in the Facets module when sorting results using term weight, causing the following deprecation warning:

Deprecated function: Creation of dynamic property Drupal\facets\Result\Result::$termWeight is deprecated in Drupal\facets\Plugin\facets\processor\TermWeightWidgetOrderProcessor->sortResults() (line 91 of modules/contrib/facets/src/Plugin/facets/processor/TermWeightWidgetOrderProcessor.php).

Steps to reproduce

  • Install the Facets module and set up a facet that uses the Term Weight Widget Order processor.
  • Use PHP 8.2 or later.
  • Perform a search or view a page where the facet is displayed.
  • Observe the deprecation warning in the log or on the page.

Proposed resolution

To resolve the issue and prevent the use of dynamic properties, the termWeight property should be explicitly declared in the Result class and ResultInterface. Additionally, use proper setter and getter methods to manage the property.

Update the TermWeightWidgetOrderProcessor::sortResults() method to use the getter and setter instead of directly assigning or accessing the dynamic property

Remaining tasks

User interface changes

None

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇯🇴Jordan mohammad-fayoumi Amman

Live updates comments and jobs are added and updated live.
  • PHP 8.2

    The issue particularly affects sites running on PHP version 8.2.0 or later.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024