Make WordPress Core


Ignore:
Timestamp:
09/09/2021 01:47:17 PM (5 years ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in WP_Upgrader_Skin::feedback().

In the parent class, renames the parameter $string to $feedback.
Why? string is a PHP reserved keyword.

In each child class: renames the parameter to match the parent's method signature.

Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Changes for readability:

  • @since clearly specifies the original parameter name and its new name as well as why the change happened.

Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader-skin.php

    r49675 r51781  
    187187        /**
    188188         * @since 2.8.0
    189          *
    190          * @param string $string
    191          * @param mixed  ...$args Optional text replacements.
    192          */
    193         public function feedback( $string, ...$args ) {
    194                 if ( isset( $this->upgrader->strings[ $string ] ) ) {
    195                         $string = $this->upgrader->strings[ $string ];
    196                 }
    197 
    198                 if ( strpos( $string, '%' ) !== false ) {
     189         * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
     190         *
     191         * @param string $feedback Message data.
     192         * @param mixed  ...$args  Optional text replacements.
     193         */
     194        public function feedback( $feedback, ...$args ) {
     195                if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
     196                        $feedback = $this->upgrader->strings[ $feedback ];
     197                }
     198
     199                if ( strpos( $feedback, '%' ) !== false ) {
    199200                        if ( $args ) {
    200                                 $args   = array_map( 'strip_tags', $args );
    201                                 $args   = array_map( 'esc_html', $args );
    202                                 $string = vsprintf( $string, $args );
     201                                $args     = array_map( 'strip_tags', $args );
     202                                $args     = array_map( 'esc_html', $args );
     203                                $feedback = vsprintf( $feedback, $args );
    203204                        }
    204205                }
    205                 if ( empty( $string ) ) {
    206                         return;
    207                 }
    208                 show_message( $string );
     206                if ( empty( $feedback ) ) {
     207                        return;
     208                }
     209                show_message( $feedback );
    209210        }
    210211
Note: See TracChangeset for help on using the changeset viewer.