[wp-trac] [WordPress Trac] #56467: Update @wordpress packages and backport changes from Gutenberg plugin into Core

WordPress Trac noreply at wordpress.org
Tue Sep 27 02:28:28 UTC 2022


#56467: Update @wordpress packages and backport changes from Gutenberg plugin into
Core
--------------------------------------+------------------------------
 Reporter:  Bernhard Reiter           |       Owner:  Bernhard Reiter
     Type:  task (blessed)            |      Status:  assigned
 Priority:  normal                    |   Milestone:  6.1
Component:  Editor                    |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------

Comment (by jrf):

 While looking at the tests now, I've found that
 [https://github.com/WordPress/wordpress-develop/pull/3199 PR 3199] as
 committed in [54156] introduces four new incompatibilities with PHP 8.2.

 The tests committed with that same PR are insufficient and did not flag
 the problem. The tests committed in [54211] luckily did flag the problem.


 The problem is with the following code:
 {{{#!php
 <?php
 class WP_Style_Engine {
         const BLOCK_STYLE_DEFINITIONS_METADATA = array(
                 /* <snip> */
                 'border'     => array(
                         /* <snip> */
                         'top'    => array(
                                 'value_func' =>
 'static::get_individual_property_css_declarations',
                                 'path'       => array( 'border', 'top' ),
                                 'css_vars'   => array(
                                         'color' => '--wp--preset--
 color--$slug',
                                 ),
                         ),
                         'right'  => array(
                                 'value_func' =>
 'static::get_individual_property_css_declarations',
                                 'path'       => array( 'border', 'right'
 ),
                                 'css_vars'   => array(
                                         'color' => '--wp--preset--
 color--$slug',
                                 ),
                         ),
                         'bottom' => array(
                                 'value_func' =>
 'static::get_individual_property_css_declarations',
                                 'path'       => array( 'border', 'bottom'
 ),
                                 'css_vars'   => array(
                                         'color' => '--wp--preset--
 color--$slug',
                                 ),
                         ),
                         'left'   => array(
                                 'value_func' =>
 'static::get_individual_property_css_declarations',
                                 'path'       => array( 'border', 'left' ),
                                 'css_vars'   => array(
                                         'color' => '--wp--preset--
 color--$slug',
                                 ),
                         ),
                 ),
                 /* <snip> */
         );

         /* <snip> */
 }
 }}}

 Each of these definitions use `'value_func' =>
 'static::get_individual_property_css_declarations'`.
 That syntax for declaring a callable is deprecated as of PHP 8.2 and will
 result in a fatal error as of PHP 9.0.

 Changing this may require an architectural change to the class.

 To explain:
 1. The typical PHP-cross-version replacement for
 `'static::get_individual_property_css_declarations'` would be  `array(
 static::class, 'get_individual_property_css_declarations' )`.
 2. However, `static::class` cannot be used in a constant declaration as
 constant values have to be ''constant'' and how `static::class` resolves
 can change at runtime depending on the class hierarchy.


 I'd like to understand why the choice was made to use `static::` in these
 declarations.
 I currently do not see any class within WP Core which extends the
 `WP_Style_Engine` class, so why is `static::` being used instead of
 `self::` ?


 As for solution directions:
 * If `static::` was not used intentional and can be replaced with
 `self::`, the callables need to be rewritten to `array( self::class,
 'get_individual_property_css_declarations' )`.
 * If `static::` ''was'' used intentionally, an architectural change is
 needed as the callable cannot be declared like that in the constant.
     * Changing the constant to a `private` property without the callables
 and adding them to the array in the class constructor is not an option as
 the class only contains static method and does not seem to be intended to
 be instantiated.
     * Changing the constant to a `private static` property is not an
 option either, as same as constants and non-static properties, the initial
 value for a property needs to be ''constant''.

 In other words: If `static::` was used intentionally, the class will
 probably need a rethink...

 As this is a new class and any architectural change in it in the future
 would be considered a breaking change, this **MUST** be fixed before WP
 6.1 is released.


 And for the love of code, please, please add better tests to safeguard
 against these kind of problems and check the PHP 8.1 and 8.2 test logs to
 prevent introducing new issues like this.


 Also see: https://wiki.php.net/rfc/deprecate_partially_supported_callables

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56467#comment:242>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list