Make WordPress Core

Changeset 55117


Ignore:
Timestamp:
01/23/2023 03:52:18 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/functions.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:

  • Renames the $array parameter to $input_array in wp_recursive_ksort().
  • Moves the function next to other array-related functions for consistency.

Follow-up to [53129], [54929].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r55054 r55117  
    48784878
    48794879/**
     4880 * Sorts the keys of an array alphabetically.
     4881 *
     4882 * The array is passed by reference so it doesn't get returned
     4883 * which mimics the behavior of `ksort()`.
     4884 *
     4885 * @since 6.0.0
     4886 *
     4887 * @param array $input_array The array to sort, passed by reference.
     4888 */
     4889function wp_recursive_ksort( &$input_array ) {
     4890    foreach ( $input_array as &$value ) {
     4891        if ( is_array( $value ) ) {
     4892            wp_recursive_ksort( $value );
     4893        }
     4894    }
     4895
     4896    ksort( $input_array );
     4897}
     4898
     4899/**
    48804900 * Accesses an array in depth based on a path of keys.
    48814901 *
     
    84308450    return abs( (float) $expected - (float) $actual ) <= $precision;
    84318451}
    8432 
    8433 /**
    8434  * Sorts the keys of an array alphabetically.
    8435  * The array is passed by reference so it doesn't get returned
    8436  * which mimics the behavior of ksort.
    8437  *
    8438  * @since 6.0.0
    8439  *
    8440  * @param array $array The array to sort, passed by reference.
    8441  */
    8442 function wp_recursive_ksort( &$array ) {
    8443     foreach ( $array as &$value ) {
    8444         if ( is_array( $value ) ) {
    8445             wp_recursive_ksort( $value );
    8446         }
    8447     }
    8448     ksort( $array );
    8449 }
Note: See TracChangeset for help on using the changeset viewer.