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

Issue fork facets-3482015

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

mohammad-fayoumi created an issue. See original summary.

mohammad-fayoumi’s picture

StatusFileSize
new3.22 KB

Creating a static patch file for the latest stable version 3.0.0-beta1

mohammad-fayoumi’s picture

Status: Active » Needs review
joseph.olstad’s picture

Status: Needs review » Needs work

PHPUnit is failing on this change.

joseph.olstad’s picture

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

herved’s picture

Status: Needs work » Needs review

Sorry for the noise, I didn't know if I could rebase the existing MR, so I created a new one.
Tests are passing, the branch only needed to be rebased.
All credits to mohammad-fayoumi

joseph.olstad’s picture

ok thanks for that.

There's still many others listed if you're ambitious. Most of the ones excluding dependency injection should be done sooner than later.

https://git.drupalcode.org/issue/facets-3482015/-/jobs/4157965

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

With that said, baby steps, suggest making a new issue for the others.

herved’s picture

Sure, I can create an issue for phpstan.
Why excluding DI ? as it breaks backwards compatibility ?

joseph.olstad’s picture

@herved , feel free to work on the DI also, it's just that a large amount of code changes will require rerolled patches everywhere, this is fine, I think these phpstan errors are a good thing to fix.

herved’s picture

impol’s picture

StatusFileSize
new3.56 KB

Adding a static patch.

liam morland’s picture

Issue tags: -remove deprecated

  • strykaizer committed 40d37cc7 on 3.0.x authored by herved
    [#3482015] fix: In PHP 8.2+, the creation of dynamic properties is...
strykaizer’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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