View's ResultRow uses deprecated dynamic properties

Created on 18 April 2022, about 2 years ago
Updated 30 March 2023, over 1 year ago

Problem/Motivation

See parent issue. Dynamic properties on PHP objects is going to be deprecated in the next minor and removed in the next major version of PHP requiring ResultRow to track all properties and provide storage for dynamic data.

Steps to reproduce

Test views in PHP 8.2

php8.2 ./vendor/bin/phpunit -c core core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing Drupal\Tests\views\Unit\Plugin\query\SqlTest
.........                                                           9 / 9 (100%)

Time: 00:00.054, Memory: 14.00 MB

OK (9 tests, 33 assertions)

Remaining self deprecation notices (26)

  11x: Creation of dynamic property Drupal\views\ResultRow::$id is deprecated
    3x in SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision from Drupal\Tests\views\Unit\Plugin\query
    3x in SqlTest::testLoadEntitiesWithRelationship from Drupal\Tests\views\Unit\Plugin\query
    3x in SqlTest::testLoadEntitiesWithRevisionOfSameEntityType from Drupal\Tests\views\Unit\Plugin\query
    2x in SqlTest::testLoadEntitiesWithNonEntityRelationship from Drupal\Tests\views\Unit\Plugin\query

  6x: Creation of dynamic property Drupal\views\ResultRow::$entity_second__id is deprecated
    3x in SqlTest::testLoadEntitiesWithRelationship from Drupal\Tests\views\Unit\Plugin\query
    3x in SqlTest::testLoadEntitiesWithRelationshipAndRevision from Drupal\Tests\views\Unit\Plugin\query

  6x: Creation of dynamic property Drupal\views\ResultRow::$vid is deprecated
    3x in SqlTest::testLoadEntitiesWithRevision from Drupal\Tests\views\Unit\Plugin\query
    3x in SqlTest::testLoadEntitiesWithRelationshipAndRevision from Drupal\Tests\views\Unit\Plugin\query

  3x: Creation of dynamic property Drupal\views\ResultRow::$entity_first__revision__vid is deprecated
    3x in SqlTest::testLoadEntitiesWithRevisionOfSameEntityType from Drupal\Tests\views\Unit\Plugin\query

...

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

10.1

Component
Views 

Last updated 25 minutes ago

Created by

🇺🇸United States neclimdul Houston, TX

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France andypost

    @neclimdul any idea how to move with it?

  • 🇫🇷France andypost

    let's see this way

  • 🇫🇷France andypost

    Fix one test and ensure NULL processed via array_key_exists()

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Seems #34 had some failures.

  • Assigned to mondrake
  • 🇮🇹Italy mondrake 🇮🇹

    I'll give a try to this. In fact, this issue would be the major blocker for 📌 Deprecate support for unused \PDO::FETCH_* modes Fixed . There, I'll be trying to remove usage of \PDO::FETCH_CLASS fetch mode. That mode is in fact a bit in contraddiction with the philosophy of PHP 8.2 that started tightening on usage of dynamic properties.

  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • 🇳🇱Netherlands daffie

    All the code changes look good to me.
    The #[\AllowDynamicProperties] has been removed from the class.
    Testing has been added.
    For me it is RTBC.

  • 🇨🇭Switzerland Berdir Switzerland

    This gets rid of the attribute but doesn't really address #2.

    I don't quite understand why this adds hasColumn() but no other explicit methods to access the data. either we add get as well or we don't have has either? __isset() exists too? Ah, I I see, it's to replace the property exists check. Unsure about the name too.

    I don't think moving to an array from undefined properties is a performance problem, if we're concerned about that then we should probably not rely on magic methods. array_key_exists() is also slower than isset(), if we're concened about performance?

  • 🇮🇹Italy mondrake 🇮🇹

    #58 for sure if someone wants to develop a full fledged API according to #2, they may do so. In any case the magic methods will have to stay (even though deprecated) till next major. I think the point is more whether to do it here or in a following issue.

    My motivation here is #36, I will not pursue any of the above further.

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    We're changing from if (property_exists($row, $this->aliases[$column])) { to if ($row->hasColumn($this->aliases[$column])) { - any contrib code that does this will break. As pointed out earlier dynamic properties on \stdClass are not deprecated so we're not really making a change we have to make here. So looking at contrib we'll break things see https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs... - plus if people are doing it in contrib then it will be done in custom code too.

Production build 0.69.0 2024