Make WordPress Core

09/09/2021 02:31:13 PM (3 years ago)

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

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.
  • In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.

Follow-up to [19995], [32806].

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

1 edited


  • trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

    r49624 r51783  
    654654     *
    655655     * @since 4.3.0
    656      *
    657      * @param array $menu_item_value The value to sanitize.
     656     * @since 5.9.0 Renamed `$menu_item_value` to `$value` for PHP 8 named parameter support.
     657     *
     658     * @param array $value The menu item value to sanitize.
    658659     * @return array|false|null|WP_Error Null or WP_Error if an input isn't valid. False if it is marked for deletion.
    659660     *                                   Otherwise the sanitized value.
    660661     */
    661     public function sanitize( $menu_item_value ) {
     662    public function sanitize( $value ) {
     663        // Restores the more descriptive, specific name for use within this method.
     664        $menu_item_value = $value;
    662666        // Menu is marked for deletion.
    663667        if ( false === $menu_item_value ) {
Note: See TracChangeset for help on using the changeset viewer.