PHP 8.2 - Deprecated function: Drupal\facets\Result\Result::$transliterateDisplayValue

Created on 4 December 2023, about 1 year ago

Problem/Motivation

While testing PHP 8.2 compatability on the Drupal 10 build I'm maintaining the dblog produced the following error:

PHP 8.2 explicitly removed this feature:
https://wiki.php.net/rfc/deprecate_dynamic_properties

[code]
Deprecated function: Creation of dynamic property Drupal\facets\Result\Result::$transliterateDisplayValue is deprecated in Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor->sortResults() (line 75 of /srv/drupal/docroot/modules/contrib/facets/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php)
#0 /srv/drupal/docroot/core/includes/bootstrap.inc(164): _drupal_error_handler_real()
#1 /srv/drupal/docroot/modules/contrib/facets/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php(75): _drupal_error_handler()
#2 /srv/drupal/docroot/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php(541): Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor->sortResults()
#3 [internal function]: Drupal\facets\FacetManager\DefaultFacetManager->Drupal\facets\FacetManager\{closure}()
#4 /srv/drupal/docroot/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php(538): uasort()
#5 /srv/drupal/docroot/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php(369): Drupal\facets\FacetManager\DefaultFacetManager->sortFacetResults()
#6 /srv/drupal/docroot/modules/contrib/facets/src/FacetManager/DefaultFacetManager.php(420): Drupal\facets\FacetManager\DefaultFacetManager->processBuild()
#7 /srv/drupal/docroot/modules/contrib/facets/src/Plugin/Block/FacetBlock.php(91): Drupal\facets\FacetManager\DefaultFacetManager->build()
#8 /srv/drupal/docroot/modules/contrib/facets_block/src/Plugin/Block/FacetsBlock.php(233): Drupal\facets\Plugin\Block\FacetBlock->build()
#9 /srv/drupal/docroot/modules/contrib/facets_block/src/Plugin/Block/FacetsBlock.php(287): Drupal\facets_block\Plugin\Block\FacetsBlock->buildFacets()
#10 /srv/drupal/docroot/core/modules/block/src/BlockViewBuilder.php(171): Drupal\facets_block\Plugin\Block\FacetsBlock->build()
#11 [internal function]: Drupal\block\BlockViewBuilder::preRender()
#12 /srv/drupal/docroot/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(111): call_user_func_array()
#13 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(797): Drupal\Core\Render\Renderer->doTrustedCallback()
#14 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(386): Drupal\Core\Render\Renderer->doCallback()
#15 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#16 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(160): Drupal\Core\Render\Renderer->render()
#17 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(592): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
#18 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(159): Drupal\Core\Render\Renderer->executeInRenderContext()
#19 /srv/drupal/docroot/core/lib/Drupal/Core/Render/Renderer.php(175): Drupal\Core\Render\Renderer->renderPlain()
#20 /srv/drupal/docroot/core/modules/big_pipe/src/Render/BigPipe.php(693): Drupal\Core\Render\Renderer->renderPlaceholder()
#21 /srv/drupal/docroot/core/modules/big_pipe/src/Render/BigPipe.php(547): Drupal\big_pipe\Render\BigPipe->renderPlaceholder()
#22 /srv/drupal/docroot/core/modules/big_pipe/src/Render/BigPipe.php(305): Drupal\big_pipe\Render\BigPipe->sendPlaceholders()
#23 /srv/drupal/docroot/core/modules/big_pipe/src/Render/BigPipeResponse.php(112): Drupal\big_pipe\Render\BigPipe->sendContent()
#24 /srv/drupal/vendor/symfony/http-foundation/Response.php(423): Drupal\big_pipe\Render\BigPipeResponse->sendContent()
#25 /srv/drupal/docroot/index.php(20): Symfony\Component\HttpFoundation\Response->send()
#26 {main}
[/code]

Steps to reproduce

When viewing any faceted result set the error is produced per record. Resulting 1000s of errors per page view per visitor!

Proposed resolution

Perhaps reference the work of the team on a similar, yet different issue?
https://www.drupal.org/project/facets/issues/3336646 🐛 PHP 8.2 compatibility for the 2.0.x branch Fixed

Remaining tasks

Restructure the class parameters and get/set functions to suppress the error per record/field?

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇺🇸United States emptyvoid

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

  • Issue created by @emptyvoid
  • 🇺🇸United States emptyvoid

    While technically the listed patch is for the 2.x branch applying it to the 3.x branch suppresses the error.

    https://www.drupal.org/files/issues/2023-01-26/3336646-2.patch

  • Assigned to mohd sahzad
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    425 pass
  • 🇮🇳India mohd sahzad

    I have fixed this issue

  • I'm on
    Drupal Version: 10.2.0
    Facets 2.0.6

    and after updating to
    PHP 8.2.13 (I also tested with PHP 8.3 -> getting the same results as PHP 8.2)

    I got multiple deprecated function messages

    "Deprecated function: Creation of dynamic property Drupal\facets\Result\Result::$transliterateDisplayValue is deprecated in Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor->sortResults() (line 72)..."

    I installed patch fexed-transliterateDisplayValue-15345798.patch
    but did not work - composer update was failing to apply the patch, since the sortResults() function in Facets 2.0.6 version is different than the one in the patch (the "get()" function is not defined)

    This is my current 'sortResults' function defined in "DisplayValueWidgetOrderProcessor"

      /**
       * {@inheritdoc}
       */
      public function sortResults(Result $a, Result $b) {
        // Get the transliterate values only once.
        if (!isset($a->transliterateDisplayValue)) {
          $a->transliterateDisplayValue = $this->transliteration->removeDiacritics($a->getDisplayValue());
        }
        if (!isset($b->transliterateDisplayValue)) {
          $b->transliterateDisplayValue = $this->transliteration->removeDiacritics($b->getDisplayValue());
        }
    
        // Return the sort value.
        if ($a->transliterateDisplayValue == $b->transliterateDisplayValue) {
          return 0;
        }
        return strnatcasecmp($a->transliterateDisplayValue, $b->transliterateDisplayValue);
      }

    so I tweaked the #5 patch (removing the get() function and make it look like:

    -   * {@inheritdoc}
    -   */
    + * {@inheritdoc}
    + */
       public function sortResults(Result $a, Result $b) {
         // Get the transliterate values only once.
    -    if (!isset($a->transliterateDisplayValue)) {
    -      $a->transliterateDisplayValue = $this->transliteration->removeDiacritics($a->getDisplayValue());
    +    $transliterateValueA = $a->transliterateDisplayValue;
    +    if (!$transliterateValueA) {
    +        $transliterateValueA = $this->transliteration->removeDiacritics($a->getDisplayValue());
    +        $a->set('transliterateDisplayValue', $transliterateValueA);
         }
    -    if (!isset($b->transliterateDisplayValue)) {
    -      $b->transliterateDisplayValue = $this->transliteration->removeDiacritics($b->getDisplayValue());
    +
    +    $transliterateValueB = $b->transliterateDisplayValue;
    +    if (!$transliterateValueB) {
    +        $transliterateValueB = $this->transliteration->removeDiacritics($b->getDisplayValue());
    +        $b->set('transliterateDisplayValue', $transliterateValueB);
         }
     
         // Return the sort value.
    -    if ($a->transliterateDisplayValue == $b->transliterateDisplayValue) {
    -      return 0;
    +    if ($transliterateValueA == $transliterateValueB) {
    +        return 0;
         }
    -    return strnatcasecmp($a->transliterateDisplayValue, $b->transliterateDisplayValue);
    +
    +    return strnatcasecmp($transliterateValueA, $transliterateValueB);
       }
     
     }

    by doing so, I was able to successfully install the patch through 'composer update'

    however, this did not fix the deprecated function message; getting

    Deprecated function: Creation of dynamic property Drupal\facets\Result\Result::$transliterateDisplayValue is deprecated in Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor->sortResults() (line 75 ...

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    Patch Failed to Apply
  • 🇺🇸United States emptyvoid

    Rerolled for 3 beta 1

  • 🇺🇸United States emptyvoid

    created a new patch with some missing elements for the results class..
    But it looks like I can't upload patches anymore so..

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    Patch Failed to Apply
  • 🇺🇸United States emptyvoid

    Re-rolled patch to be based on the root of the module.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    149 pass, 61 fail
  • 🇺🇸United States emptyvoid

    Rerolled based on dev branch

  • The last submitted patch, 12: facets-3-beta-3406085-2024-10-10.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • 🇪🇸Spain aleix

    Adding new patch with proper CS and resultInterface new methods, for 3.0.0-beta1 .

  • 🇪🇸Spain aleix

    The same as #14 but for 3.0.x

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    PHPLint Failed
  • 🇪🇸Spain aleix

    reroll for 3.0.x

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    424 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    424 pass, 2 fail
  • 🇫🇷France MacSim

    Isn't this issue a duplicate of https://www.drupal.org/project/facets/issues/3336646 🐛 PHP 8.2 compatibility for the 2.0.x branch Fixed ?

  • Updating patch from #14 was getting below error

    Error: Cannot access protected property Drupal\facets\Result\Result::$termWeight in Drupal\facets\Plugin\facets\processor\TermWeightWidgetOrderProcessor->sortResults() (line 91 of modules/contrib/facets/src/Plugin/facets/processor/TermWeightWidgetOrderProcessor.php).

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 10 months ago
    Patch Failed to Apply
  • 🇬🇧United Kingdom fonant

    Patch #18 works for me to stop the watchdog logs filling up with deprecation warnings. Thanks @gurvindersingh!

  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    Hard disagree that this should be changed to setters/getters. Especially if the properties stay public.

    PS: It seems you (like many others – it's really easy to misinterpret) are confused by the "Issue tags" field. As the guidelines state, they aren't meant for free text tags related to the issue, but only for specific categorization purposes, usually by module maintainers.
    So, if you aren't sure your current usage is correct, please just leave the field empty, especially the name of the module is not helpful at all.

    Can we add 2 branches, one for 2.x and one for 3.x?

  • 🇺🇸United States joshmiller Indianapolis, Indiana, USA

    Chiming in here that this error, unnoticed by our team, took down urban.org briefly a few weeks ago when we updated to PHP 8.2.

    Whatever the fix is, we're going to test out this patch, and we will need something to resolve this error.

    How did this take down our elite Pantheon site? It eventually filled up our database with almost 500 GB of watchdog entries with thousands of warnings per record per user.

  • 🇺🇸United States jkwilson

    Following. Same issue after moving to PHP 8.2: watchdog logs filled up the server and briefly took the site down. Have applied patch #18. More thanks @gurvindersingh!

  • 🇹🇭Thailand Nick Hope

    #18 works for me. PHP 8.3.2 (DDEV). Drupal 10.2.6. Facets 3.0.0-beta1.

  • 🇸🇬Singapore clairero

    Patch #18 is works for me too. I'm running Drupal 10.2.4 with PHP 8.2.18. Thanks @gurvindersingh!

  • 🇮🇳India Anita verma

    I am unable to add Facets and facing Deprecated php error. I applied Patch #18 it is works to me. I'm running Drupal 10.2.4 with PHP 8.2.

  • Status changed to Needs review 7 months ago
  • First commit to issue fork.
  • Merge request !218Resolve #3406085 "Result dynamic property 3.x" → (Open) created by heddn
  • Pipeline finished with Failed
    6 months ago
    Total: 639s
    #197331
  • Status changed to Postponed: needs info 6 months ago
  • 🇫🇮Finland sokru

    Isn't this duplicate of 📌 PHP 8.2 compatibility Fixed ? At least based on the issue summary and (failing) MR, this issue should be closed as duplicate.

  • 🇧🇪Belgium fernly

    Creation of dynamic properties is deprecated since PHP 8.2 and will throw a fatal error as from PHP 9.0.
    You can let the class opt in by using the #[\AllowDynamicProperties] attribute as a temp fix.

    The same notice is thrown for Drupal\facets\Result\Result::$termWeight.

  • Status changed to Needs work 4 months ago
  • 🇺🇸United States mile23 Seattle, WA

    Can confirm that this issue still exists for 3.0.0-beta1.

    % ddev composer show drupal/facets | grep versions
    versions : * 3.0.0-beta1
    

    The workaround is don't show deprecation errors to users in production. :-)

    I'm not very familiar with the code for this module, but it looks like the solution in #28 is about right.

  • Status changed to Closed: duplicate 4 months ago
  • 🇫🇮Finland sokru

    @mile23: Latest release 3.0.0-beta1 is from 2022, the duplicate issue 📌 PHP 8.2 compatibility Fixed was committed to 3.0.x branch on 2023. So you should either use dev-branch or pick the patch for 3.0.0-beta1 from mentioned issue.

    The maintainers should create a new release for Facets

  • 🇮🇳India ajit dalal

    Adding duplicate variable with 2.x latest version
    + /**
    + * The facet transliterate display value.
    + *
    + * @var string
    + */
    + protected $transliterateDisplayValue;
    +
    + /**
    + * The term weight.
    + *
    + * @var int
    + */
    + protected $termWeight;
    +

  • 🇺🇸United States csmdgl

    Re-roll and static patch of #28.

Production build 0.71.5 2024