Make WordPress Core


Ignore:
Timestamp:
04/26/2022 01:30:47 PM (23 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-query.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 $query_vars in WP_Query::fill_query_vars().
  • Renames the $default parameter to $default_value in WP_Query::get().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276].

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

File:
1 edited

Legend:

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

    r53175 r53277  
    537537     * @since 4.5.0 Removed the `comments_popup` public query variable.
    538538     *
    539      * @param array $array Defined query variables.
     539     * @param array $query_vars Defined query variables.
    540540     * @return array Complete query variables with undefined ones filled in empty.
    541541     */
    542     public function fill_query_vars( $array ) {
     542    public function fill_query_vars( $query_vars ) {
    543543        $keys = array(
    544544            'error',
     
    581581
    582582        foreach ( $keys as $key ) {
    583             if ( ! isset( $array[ $key ] ) ) {
    584                 $array[ $key ] = '';
     583            if ( ! isset( $query_vars[ $key ] ) ) {
     584                $query_vars[ $key ] = '';
    585585            }
    586586        }
     
    605605
    606606        foreach ( $array_keys as $key ) {
    607             if ( ! isset( $array[ $key ] ) ) {
    608                 $array[ $key ] = array();
    609             }
    610         }
    611         return $array;
     607            if ( ! isset( $query_vars[ $key ] ) ) {
     608                $query_vars[ $key ] = array();
     609            }
     610        }
     611
     612        return $query_vars;
    612613    }
    613614
     
    17481749     *
    17491750     * @since 1.5.0
    1750      * @since 3.9.0 The `$default` argument was introduced.
    1751      *
    1752      * @param string $query_var Query variable key.
    1753      * @param mixed  $default  Optional. Value to return if the query variable is not set. Default empty string.
     1751     * @since 3.9.0 The `$default_value` argument was introduced.
     1752     *
     1753     * @param string $query_var     Query variable key.
     1754     * @param mixed  $default_value Optional. Value to return if the query variable is not set. Default empty string.
    17541755     * @return mixed Contents of the query variable.
    17551756     */
    1756     public function get( $query_var, $default = '' ) {
     1757    public function get( $query_var, $default_value = '' ) {
    17571758        if ( isset( $this->query_vars[ $query_var ] ) ) {
    17581759            return $this->query_vars[ $query_var ];
    17591760        }
    17601761
    1761         return $default;
     1762        return $default_value;
    17621763    }
    17631764
Note: See TracChangeset for help on using the changeset viewer.