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
Comment #2
neclimdulApologies 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.
Comment #3
neclimdulComment #4
mondrakeVery close to #3274474: Fix 'Access to an undefined property' PHPStan L0 errors
Comment #5
neclimdulAbsolutely related, thanks. That'll fix a lot of accidental one's for sure. Was seeing quite a few of those for sure.
Comment #6
cilefen commentedComment #7
gábor hojtsyDiscussing 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?
Comment #8
xjmI think this should be a child of the main PHP 8.2 meta, but also should be a meta in its own right.
Comment #9
andypostComment #10
gábor hojtsyReparenting to #3283358: [META] Make Drupal 9/10 compatible with PHP 8.2.
Comment #11
gábor hojtsyComment #12
andypostThere's a hack to prevent the message https://php.watch/versions/8.2/AllowDynamicProperties
#[AllowDynamicProperties]attributeComment #13
andypostUsed to re-roll #2531564-169: Fix leaky and brittle container serialization solution but it does not solve steam of deprecation notices
Comment #14
andypostThis issue is partially blocked on upstream https://github.com/phpstan/phpstan-src/pull/1478 as CI fails https://www.drupal.org/pift-ci-job/2363989
Comment #15
andypostAdded child #3259716: Replace usages of static::class . '::methodName' to first-class callable syntax static::method(...) and appended IS with https://php.watch/versions/8.2/partially-supported-callable-deprecation
Comment #16
andypostSorry, mixed issues, please ignore #15
Comment #17
andypostTo proceed here Phpstan needs upgrade to 1.8.0 at least, so filed #3293933: Upgrade phpstan/phpstan to 1.8.1
Comment #18
andypostComment #19
andypostInitial run of CI shows lots of issues about "::serviceId" property
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
Comment #20
andypost1.8.1 is out so I reopened #3293933: Upgrade phpstan/phpstan to 1.8.1
Comment #21
andypostCreated testing issue to minimize noise #3295821: Ignore: patch testing issue for PHP 8.2 attributes
Added new child issue #3295813: ViewsEntitySchemaSubscriber access undefined property of View
Comment #22
andypostFiled child issue to find solution #3298731: Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2
Comment #23
andypostFiled child #3298906: Fix \Drupal\Tests\Core\Test\TestSetupTraitTest::testChangeDatabasePrefix() on PHP 8.2
Comment #24
andypostFiled child #3298923: Fix ProtectedUserFieldConstraintValidatorTest to not trigger deprecations on PHP 8.2
Comment #25
andypostAnother small issue to fix Callable's syntax #3299327: Replace deprecated static::method() calls for PHP 8.2
Comment #26
andypostThe related #2363315: Refactor Database:: static properties and methods could help to clean-up some usage
Comment #27
andypostFiled #3299853: Apply #[\AllowDynamicProperties] attribute to base classes to make PHP 8.2 log size sane and follow-up #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute
Comment #28
andypostone more child commited #3298923: Fix ProtectedUserFieldConstraintValidatorTest to not trigger deprecations on PHP 8.2
Comment #29
andypostdelComment #30
andypostComment #31
andypostUpdated IS with must-haves
- #2531564: Fix leaky and brittle container serialization solution
- #3298906: Fix \Drupal\Tests\Core\Test\TestSetupTraitTest::testChangeDatabasePrefix() on PHP 8.2
- #3298731: Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2
- #3274474: Fix 'Access to an undefined property' PHPStan L0 errors - to pass phpstan
And could-haves
- #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute - tons of sub-issues to define all properties
- #3210004: Rss views style plugin channel_elements property needs rename
Comment #32
andypostremoved as not must have - #2363315: Refactor Database:: static properties and methods
Comment #33
andypostremoved #3210004: Rss views style plugin channel_elements property needs rename from summary as clean-up and unrelated as properties are defined
Comment #34
andypostComment #35
andypostfixed #3298906: Fix \Drupal\Tests\Core\Test\TestSetupTraitTest::testChangeDatabasePrefix() on PHP 8.2
Comment #36
andypostFiled one more child #3308744: Fix magic connection property access from \Drupal\Core\FileTransfer\FileTransfer::__get()
Comment #37
andypostThere's only 3 issues left
- #2839195: Add a method to access the original property
- #3298731: Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2
- #3308744: Fix magic connection property access from \Drupal\Core\FileTransfer\FileTransfer::__get()
Comment #38
berdir> - #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.
Comment #39
andypostFiled aggregated patch to make sure #3295821-90: Ignore: patch testing issue for PHP 8.2 attributes
Personally +1 fix "original", hope at allowed ATM
Comment #40
andypost@Berdir the patch is required as it fixes ~800 tests
Comment #41
berdirI 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...
Comment #42
andypostFiled new child issues
- #3309745: Fix dynamic property deprecations and other unit test failures for PHP 8.2
- #3309748: Define missing object properties on non-testing classes for PHP 8.2
- #3309750: Fix callable syntax for PHP 8.2 in Views.php
Comment #43
bbrala#3298731: Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2 fixed.
Comment #44
bbralaComment #45
wim leersThe 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 😅
Comment #46
andypostI think this fixed as there's no deprecations anymore and remaining goal is #3299855: [META] Get rid of #[\AllowDynamicProperties] attribute
Comment #48
cilefen commented#3328005: [9.5.x only] PHP 8.2 Creation of dynamic property Drupal\pgsql\Driver\Database\pgsql\Select::$alterMetaData is deprecated