[wp-trac] [WordPress Trac] #56513: PHP 8.2: silence dynamic properties deprecation notices

WordPress Trac noreply at wordpress.org
Mon Sep 5 12:53:03 UTC 2022


#56513: PHP 8.2: silence dynamic properties deprecation notices
--------------------------+------------------------------------
 Reporter:  jrf           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  6.1
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:  has-patch php82 commit
  Focuses:                |
--------------------------+------------------------------------
 Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2
 and are expected to become a fatal error in PHP 9.0, though this last part
 is not 100% certain yet.

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

 We can basically categorize dynamic properties into four base situations:

 || ||= Situation =||= Solution =||
 || 1. || Typo in property name || Fix the typo, either in the property as
 declared or where the property assignment happens ||
 || 2. || Known, named, dynamic property || Declare the property on the
 (parent) class ||
 || 3. || Known use of unknown dynamic properties || Declare the full set
 of magic methods on a class (preferred) or let the class extend `stdClass`
 (discouraged) ||
 || 4. || Unknown use of unknown dynamic properties || Use the
 `#[AllowDynamicProperties]` attribute on the (parent) class and/or declare
 the full set of magic methods on a class and/or let the class extend
 `stdClass` ||

 Note: the `#[AllowDynamicProperties]` attribute is expected to be a
 temporary solution and it is expected that support for the attribute will
 be removed from PHP at some point in the future.

 === Current status

 Patches have been created for Trac #56033 to explicitly declare all
 "known" dynamic properties (type 1 + 2).

 A proposal to mitigate the deprecation for the "unknown" dynamic
 properties (type 3 + 4) via traits is open in Trac #56034.

 However, it is clear that more time is needed to action that proposal.

 === Interim solution

 For the time being, I propose to add the `#[AllowDynamicProperties]`
 attribute on all parent classes in the `src` directory and classes which
 extend a class from an external dependency.

 This should buy us more time to get a long-term solution in place via
 #56034.

 The main reasons to add the attribute for now, is to silence "noise" in
 the form of:
 1. New (duplicate) Trac tickets being opened about the dynamic properties
 deprecation.
 2. WP Core tests error-ing out on the deprecation notices when run against
 PHP 8.2.
 3. Integration tests for plugins/themes error-ing out on the deprecation
 notices when run against PHP 8.2.
 4. Deprecation notices being logged in error logs on servers which have
 error logging for this turned on (not the default setup for WP).

 As an additional advantage, this will allow us to remove the `continue-on-
 error` for PHP 8.2 test runs in the foreseeable future, which will help
 prevent new PHP 8.2 incompatibilities from being introduced.

 There is already a PR open on GitHub for this ticket:
 https://github.com/WordPress/wordpress-develop/pull/3123

 If/when new classes get added to WP in the mean time (before the solution
 from #56034 is in place), tooling has been created to either update the
 current patch and/or create additional patches using the same logic as
 used to create the current patch.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56513>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list