From 005cfdbf4e60c179693ec280017cb06767643b29 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 23 Jan 2023 15:52:18 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55117 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 5d1f52e762..623a69aba0 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4876,6 +4876,26 @@ function wp_array_slice_assoc( $input_array, $keys ) { return $slice; } +/** + * Sorts the keys of an array alphabetically. + * + * The array is passed by reference so it doesn't get returned + * which mimics the behavior of `ksort()`. + * + * @since 6.0.0 + * + * @param array $input_array The array to sort, passed by reference. + */ +function wp_recursive_ksort( &$input_array ) { + foreach ( $input_array as &$value ) { + if ( is_array( $value ) ) { + wp_recursive_ksort( $value ); + } + } + + ksort( $input_array ); +} + /** * Accesses an array in depth based on a path of keys. * @@ -8429,21 +8449,3 @@ function is_php_version_compatible( $required ) { function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) { return abs( (float) $expected - (float) $actual ) <= $precision; } - -/** - * Sorts the keys of an array alphabetically. - * The array is passed by reference so it doesn't get returned - * which mimics the behavior of ksort. - * - * @since 6.0.0 - * - * @param array $array The array to sort, passed by reference. - */ -function wp_recursive_ksort( &$array ) { - foreach ( $array as &$value ) { - if ( is_array( $value ) ) { - wp_recursive_ksort( $value ); - } - } - ksort( $array ); -}