WordPress.org

Make WordPress Core

Changeset 51789


Ignore:
Timestamp:
09/09/2021 08:12:58 PM (3 weeks ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix parameter name mismatches for parent/child classes in WP_Widget::update().

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.

Adds @since to clearly specify why the change happened.

Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.

Follow-up to [10782], [25090], [26556], [40640].

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

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/inc/widgets.php

    r47550 r51789  
    263263     *
    264264     * @since Twenty Fourteen 1.0
     265     * @since Twenty Fourteen 3.3 Renamed `$instance` to `$old_instance` to match
     266     *                            parent class for PHP 8 named parameter support.
    265267     *
    266268     * @param array $new_instance New widget instance.
    267      * @param array $instance    Original widget instance.
     269     * @param array $old_instance Original widget instance.
    268270     * @return array Updated widget instance.
    269271     */
    270     function update( $new_instance, $instance ) {
    271         $instance['title']  = strip_tags( $new_instance['title'] );
    272         $instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] );
     272    function update( $new_instance, $old_instance ) {
     273        $old_instance['title']  = strip_tags( $new_instance['title'] );
     274        $old_instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] );
    273275
    274276        if ( in_array( $new_instance['format'], $this->formats, true ) ) {
    275             $instance['format'] = $new_instance['format'];
    276         }
    277 
    278         return $instance;
     277            $old_instance['format'] = $new_instance['format'];
     278        }
     279
     280        return $old_instance;
    279281    }
    280282
  • trunk/src/wp-includes/widgets/class-wp-widget-media.php

    r50995 r51789  
    260260     *
    261261     * @since 4.8.0
     262     * @since 5.9.0 Renamed `$instance` to `$old_instance` to match parent class
     263     *              for PHP 8 named parameter support.
    262264     *
    263265     * @see WP_Widget::update()
     
    266268     *
    267269     * @param array $new_instance Values just sent to be saved.
    268      * @param array $instance    Previously saved values from database.
     270     * @param array $old_instance Previously saved values from database.
    269271     * @return array Updated safe values to be saved.
    270272     */
    271     public function update( $new_instance, $instance ) {
     273    public function update( $new_instance, $old_instance ) {
    272274
    273275        $schema = $this->get_instance_schema();
     
    304306                continue;
    305307            }
    306             $instance[ $field ] = $value;
    307         }
    308 
    309         return $instance;
     308            $old_instance[ $field ] = $value;
     309        }
     310
     311        return $old_instance;
    310312    }
    311313
Note: See TracChangeset for help on using the changeset viewer.