Make WordPress Core


Ignore:
Timestamp:
09/09/2021 01:47:17 PM (4 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-bulk-upgrader-skin.php

    r46125 r51781  
    5050
    5151    /**
    52      * @param string $string
    53      * @param mixed  ...$args Optional text replacements.
     52     * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
     53     *
     54     * @param string $feedback Message data.
     55     * @param mixed  ...$args  Optional text replacements.
    5456     */
    55     public function feedback( $string, ...$args ) {
    56         if ( isset( $this->upgrader->strings[ $string ] ) ) {
    57             $string = $this->upgrader->strings[ $string ];
     57    public function feedback( $feedback, ...$args ) {
     58        if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
     59            $feedback = $this->upgrader->strings[ $feedback ];
    5860        }
    5961
    60         if ( strpos( $string, '%' ) !== false ) {
     62        if ( strpos( $feedback, '%' ) !== false ) {
    6163            if ( $args ) {
    62                 $args   = array_map( 'strip_tags', $args );
    63                 $args   = array_map( 'esc_html', $args );
    64                 $string = vsprintf( $string, $args );
     64                $args     = array_map( 'strip_tags', $args );
     65                $args     = array_map( 'esc_html', $args );
     66                $feedback = vsprintf( $feedback, $args );
    6567            }
    6668        }
    67         if ( empty( $string ) ) {
     69        if ( empty( $feedback ) ) {
    6870            return;
    6971        }
    7072        if ( $this->in_loop ) {
    71             echo "$string<br />\n";
     73            echo "$feedback<br />\n";
    7274        } else {
    73             echo "<p>$string</p>\n";
     75            echo "<p>$feedback</p>\n";
    7476        }
    7577    }
Note: See TracChangeset for help on using the changeset viewer.