Skip to content

Commit 5ebe289

Browse files
Code Modernization: Add AllowDynamicProperties attribute to all (parent) classes.
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0. There are a number of ways to mitigate this: * If it is an accidental typo for a declared property: fix the typo. * For known properties: declare them on the class. * For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in. * For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes. Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1. To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP. The logic used for this commit is as follows: * If a class already has the attribute: no action needed. * If a class does not `extend`: add the attribute. * If a class does `extend`: - If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties). - If it extends a PHP native class: add the attribute. - If it extends a class from one of WP's external dependencies: add the attribute. * In all other cases: no action — the attribute should not be needed as child classes inherit from the parent. Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details. This commit only affects classes in the `src` directory of WordPress core. * Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033. * While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately. Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties]. Follow-up to [53922]. Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath. See #56513, #56034. git-svn-id: https://develop.svn.wordpress.org/trunk@54133 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7053062 commit 5ebe289

File tree

124 files changed

+125
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+125
-0
lines changed

src/wp-admin/includes/class-custom-background.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* @since 3.0.0
1313
*/
14+
#[AllowDynamicProperties]
1415
class Custom_Background {
1516

1617
/**

src/wp-admin/includes/class-custom-image-header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* @since 2.1.0
1313
*/
14+
#[AllowDynamicProperties]
1415
class Custom_Image_Header {
1516

1617
/**

src/wp-admin/includes/class-file-upload-upgrader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @since 2.8.0
1717
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
1818
*/
19+
#[AllowDynamicProperties]
1920
class File_Upload_Upgrader {
2021

2122
/**

src/wp-admin/includes/class-wp-automatic-updater.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @since 3.7.0
1414
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
1515
*/
16+
#[AllowDynamicProperties]
1617
class WP_Automatic_Updater {
1718

1819
/**

src/wp-admin/includes/class-wp-community-events.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* @since 4.8.0
1616
*/
17+
#[AllowDynamicProperties]
1718
class WP_Community_Events {
1819
/**
1920
* ID for a WordPress user account.

src/wp-admin/includes/class-wp-debug-data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @since 5.2.0
88
*/
99

10+
#[AllowDynamicProperties]
1011
class WP_Debug_Data {
1112
/**
1213
* Calls all core functions to check for updates.

src/wp-admin/includes/class-wp-filesystem-base.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* @since 2.5.0
1313
*/
14+
#[AllowDynamicProperties]
1415
class WP_Filesystem_Base {
1516

1617
/**

src/wp-admin/includes/class-wp-importer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/**
33
* WP_Importer base class
44
*/
5+
#[AllowDynamicProperties]
56
class WP_Importer {
67
/**
78
* Class Constructor

src/wp-admin/includes/class-wp-internal-pointers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
* @since 3.3.0
1414
*/
15+
#[AllowDynamicProperties]
1516
final class WP_Internal_Pointers {
1617
/**
1718
* Initializes the new feature pointers.

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @since 3.1.0
1414
* @access private
1515
*/
16+
#[AllowDynamicProperties]
1617
class WP_List_Table {
1718

1819
/**

0 commit comments

Comments
 (0)