Problem/Motivation

PHP 8.2 has what is likely to be a hugely disruptive deprecation of dynamic properties. This is used through out core and likely to cause numerous problems. Obviously deprecation don't _break_ sites but they will introduce warnings into dev environments that capture deprecation errors and block support for PHP 9 where they will be errors.

https://wiki.php.net/rfc/deprecate_dynamic_properties

Steps to reproduce

You can compile php 8.2 and run a site and see a number of deprecation notices. Late 2022 php 8.2 should be released and we will be seeing these in phpstan and during testbot runs.

Proposed resolution

List of must have issues to start pass tests

- #2839195: Add a method to access the original property

Done
- #3308744: Fix magic connection property access from \Drupal\Core\FileTransfer\FileTransfer::__get()
- #2531564: Fix leaky and brittle container serialization solution
- #3298731: Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2
- #3274474: Fix 'Access to an undefined property' PHPStan L0 errors - to pass phpstan

And could have (could be extended)
- #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute - tons of sub-issues to define all properties

Fixes will vary. For data objects we can either add #[AllowDynamicProperties] attribute to class or there is a simple-ish hack we can apply to support.


  /**
   * Raw row data.
   *
   * @var array
   */
  private array $data = [];

  /**
   * Implements the magic method for getting object properties.
   *
   * @param $name
   *   Property name.
   *
   * @return mixed
   *   The property value.
   */
  public function &__get($name) {
    return $this->data[$name];
  }

  /**
   * Implements the magic method to determines whether a property is set.
   *
   * @param $name
   *   Property name.
   *
   * @return bool
   *   True if property is set.
   */
  public function __isset($name) {
    return isset($this->data[$name]);
  }

  /**
   * Implements the magic method to set a property.
   *
   * @param $name
   *   Property name.
   * @param mixed $value
   *   The property value.
   */
  public function __set($name, $value) {
    $this->data[$name] = $value;
  }

  /**
   * Implements the magic method to unset a property.
   *
   * @param $name
   *   Property name.
   */
  public function __unset($name) {
    unset($this->data[$name]);
  }

Some things just don't work anymore #2531564: Fix leaky and brittle container serialization solution

Remaining tasks

  • Create tasks for issues.
  • Fix issues

User interface changes

n/a . This should only affect code interfaces.

API changes

Most changes should be to data objects or just missing properties so hopefully limited. I expect this will turn up some code smell that may result in deprecation though. Also we may find other hard changes like to our service container that require complicated fixes.

Data model changes

n/a

Release notes snippet

tbd

Comments

neclimdul created an issue. See original summary.

neclimdul’s picture

Apologies if this already exists or there's a PHP 8.2 issue that would be better for this but I didn't find it and wanted to start capturing obvious code that I run across that's going to be broken by this change.

neclimdul’s picture

Issue summary: View changes
mondrake’s picture

neclimdul’s picture

Absolutely related, thanks. That'll fix a lot of accidental one's for sure. Was seeing quite a few of those for sure.

cilefen’s picture

Title: Fix dynamic propert deprecations. » Fix dynamic property deprecations
gábor hojtsy’s picture

Discussing this in the Drupal 10 readiness meeting. Should this be converted to a PHP 8.2 meta issue? (Since I don't think there is one yet)? @andypost suggested we take over this for a general PHP 8.2 META. Or do we expect more problems and this is a sub-set of the PHP 8.2 problems and should have a META above this?

xjm’s picture

I think this should be a child of the main PHP 8.2 meta, but also should be a meta in its own right.

andypost’s picture

Title: Fix dynamic property deprecations » [META] Fix dynamic property deprecations
Parent issue: » #3118149: [meta] Requirements for tagging Drupal 10.0.0-beta1
gábor hojtsy’s picture

Title: [META] Fix dynamic property deprecations » [META] Fix PHP 8.2 dynamic property deprecations
andypost’s picture

There's a hack to prevent the message https://php.watch/versions/8.2/AllowDynamicProperties

#[AllowDynamicProperties] attribute

andypost’s picture

Used to re-roll #2531564-169: Fix leaky and brittle container serialization solution but it does not solve steam of deprecation notices

andypost’s picture

andypost’s picture

andypost’s picture

To proceed here Phpstan needs upgrade to 1.8.0 at least, so filed #3293933: Upgrade phpstan/phpstan to 1.8.1

andypost’s picture

andypost’s picture

Initial run of CI shows lots of issues about "::serviceId" property

  1x: Creation of dynamic property Mock_CacheContextsManager_dff343cd::$_serviceId is deprecated
    1x in ContentTranslationManageAccessCheckTest::setUp from Drupal\Tests\content_translation\Unit\Access

For example https://dispatcher.drupalci.org/job/drupal_patches/136717/testReport/jun...

It means the related issue should be fixed via #2531564: Fix leaky and brittle container serialization solution

andypost’s picture

andypost’s picture

andypost’s picture

andypost’s picture

Another small issue to fix Callable's syntax #3299327: Replace deprecated static::method() calls for PHP 8.2

andypost’s picture

andypost’s picture

andypost’s picture

andypost’s picture

Issue summary: View changes

removed #3210004: Rss views style plugin channel_elements property needs rename from summary as clean-up and unrelated as properties are defined

andypost’s picture

Issue summary: View changes
andypost’s picture

andypost’s picture

berdir’s picture

> - #2839195: Define 'original' as property on the entity object

This should no longer be a blocker since we did #3299853: Apply #[\AllowDynamicProperties] attribute to base classes to make PHP 8.2 log size sane, you should be able to remove that. I'd still like to do that, but it's not blocking PHP 8.2.

andypost’s picture

Filed aggregated patch to make sure #3295821-90: Ignore: patch testing issue for PHP 8.2 attributes

Personally +1 fix "original", hope at allowed ATM

andypost’s picture

@Berdir the patch is required as it fixes ~800 tests

berdir’s picture

I posted a review in the test issue, the fails are becaue you missed a spot in the removal of that. I only get a single deprecation notice on HEAD on 8.2 (ViewExcecutable::$execute_time) for https://dispatcher.drupalci.org/job/drupal_patches/148449/testReport/jun...

bbrala’s picture

bbrala’s picture

Issue summary: View changes
wim leers’s picture

The issue summary lists #2839195: Add a method to access the original property as a must-have. Yet there, @Berdir wrote at #2839195-90: Add a method to access the original property that it's not a PHP 8.2 blocker.

Of the issues mentioned there, they all seem to be children of #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute, which is listed here as a could have.

So … does that mean there's nothing left to do here? I see in #42 that #3309745: Fix dynamic property deprecations and other unit test failures for PHP 8.2 is a new child issue, but got stuck there while reviewing (see #3309745-39: Fix dynamic property deprecations and other unit test failures for PHP 8.2).

What is actually next here? I'm happy to update issue summaries and links, but then I first have to be able to build a mental map for myself 😅

andypost’s picture

Status: Active » Fixed

I think this fixed as there's no deprecations anymore and remaining goal is #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute

Status: Fixed » Closed (fixed)

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