Make WordPress Core


Ignore:
Timestamp:
09/09/2021 08:12:58 PM (3 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.