Make WordPress Core

Changeset 51780


Ignore:
Timestamp:
09/09/2021 01:02:46 PM (3 years ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in Walker::end_el().

In the parent class, renames the parameter $object to $data_object.
Why? object is a PHP reserved keyword. The parameter name is selected for consistency with Walker::start_el().

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.

Follow-up to [7737], [8900], [8970], [14248], [16100], [25642], [25644], [37051], [37056].

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

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-category-checklist.php

    r51779 r51780  
    126126     *
    127127     * @since 2.5.1
     128     * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
    128129     *
    129      * @param string  $output   Used to append additional content (passed by reference).
    130      * @param WP_Term $category The current term object.
    131      * @param int     $depth    Depth of the term in reference to parents. Default 0.
    132      * @param array   $args     An array of arguments. @see wp_terms_checklist()
     130     * @param string  $output      Used to append additional content (passed by reference).
     131     * @param WP_Term $data_object The current term object.
     132     * @param int     $depth       Depth of the term in reference to parents. Default 0.
     133     * @param array   $args        An array of arguments. @see wp_terms_checklist()
    133134     */
    134     public function end_el( &$output, $category, $depth = 0, $args = array() ) {
     135    public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
    135136        $output .= "</li>\n";
    136137    }
  • trunk/src/wp-includes/class-walker-category.php

    r51779 r51780  
    255255     *
    256256     * @since 2.1.0
     257     * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
    257258     *
    258259     * @see Walker::end_el()
    259260     *
    260      * @param string $output Used to append additional content (passed by reference).
    261      * @param object $page  Not used.
    262      * @param int    $depth  Optional. Depth of category. Not used.
    263      * @param array  $args   Optional. An array of arguments. Only uses 'list' for whether should append
    264      *                       to output. See wp_list_categories(). Default empty array.
    265      */
    266     public function end_el( &$output, $page, $depth = 0, $args = array() ) {
     261     * @param string $output      Used to append additional content (passed by reference).
     262     * @param object $data_object Category data object. Not used.
     263     * @param int    $depth       Optional. Depth of category. Not used.
     264     * @param array  $args        Optional. An array of arguments. Only uses 'list' for whether should
     265     *                            append to output. See wp_list_categories(). Default empty array.
     266     */
     267    public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
    267268        if ( 'list' !== $args['style'] ) {
    268269            return;
  • trunk/src/wp-includes/class-walker-comment.php

    r51779 r51780  
    214214     *
    215215     * @since 2.7.0
     216     * @since 5.9.0 Renamed `$comment` to `$data_object` to match parent class for PHP 8 named parameter support.
    216217     *
    217218     * @see Walker::end_el()
    218219     * @see wp_list_comments()
    219220     *
    220      * @param string     $output  Used to append additional content. Passed by reference.
    221      * @param WP_Comment $comment The current comment object. Default current comment.
    222      * @param int        $depth   Optional. Depth of the current comment. Default 0.
    223      * @param array      $args    Optional. An array of arguments. Default empty array.
    224      */
    225     public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
     221     * @param string     $output      Used to append additional content. Passed by reference.
     222     * @param WP_Comment $data_object Comment data object.
     223     * @param int        $depth       Optional. Depth of the current comment. Default 0.
     224     * @param array      $args        Optional. An array of arguments. Default empty array.
     225     */
     226    public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
    226227        if ( ! empty( $args['end-callback'] ) ) {
    227228            ob_start();
    228             call_user_func( $args['end-callback'], $comment, $args, $depth );
     229            call_user_func(
     230                $args['end-callback'],
     231                $data_object, // The current comment object.
     232                $args,
     233                $depth
     234            );
    229235            $output .= ob_get_clean();
    230236            return;
  • trunk/src/wp-includes/class-walker-nav-menu.php

    r51779 r51780  
    257257     *
    258258     * @since 3.0.0
     259     * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support.
    259260     *
    260261     * @see Walker::end_el()
    261262     *
    262      * @param string   $output Used to append additional content (passed by reference).
    263      * @param WP_Post  $item   Page data object. Not used.
    264      * @param int      $depth  Depth of page. Not Used.
    265      * @param stdClass $args   An object of wp_nav_menu() arguments.
    266      */
    267     public function end_el( &$output, $item, $depth = 0, $args = null ) {
     263     * @param string   $output      Used to append additional content (passed by reference).
     264     * @param WP_Post  $data_object Menu item data object. Not used.
     265     * @param int      $depth       Depth of page. Not Used.
     266     * @param stdClass $args        An object of wp_nav_menu() arguments.
     267     */
     268    public function end_el( &$output, $data_object, $depth = 0, $args = null ) {
    268269        if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
    269270            $t = '';
  • trunk/src/wp-includes/class-walker-page.php

    r51779 r51780  
    223223     *
    224224     * @since 2.1.0
     225     * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support.
    225226     *
    226227     * @see Walker::end_el()
    227228     *
    228      * @param string  $output Used to append additional content. Passed by reference.
    229      * @param WP_Post $page  Page data object. Not used.
    230      * @param int     $depth  Optional. Depth of page. Default 0 (unused).
    231      * @param array   $args   Optional. Array of arguments. Default empty array.
    232      */
    233     public function end_el( &$output, $page, $depth = 0, $args = array() ) {
     229     * @param string  $output      Used to append additional content. Passed by reference.
     230     * @param WP_Post $data_object Page data object. Not used.
     231     * @param int     $depth       Optional. Depth of page. Default 0 (unused).
     232     * @param array   $args        Optional. Array of arguments. Default empty array.
     233     */
     234    public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
    234235        if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
    235236            $t = "\t";
  • trunk/src/wp-includes/class-wp-walker.php

    r51779 r51780  
    101101     *
    102102     * @since 2.1.0
     103     * @since 5.9.0 Renamed `$object` (a PHP reserved keyword) to `$data_object` for PHP 8 named parameter support.
    103104     * @abstract
    104105     *
    105      * @param string $output Used to append additional content (passed by reference).
    106      * @param object $object The data object.
    107      * @param int    $depth  Depth of the item.
    108      * @param array  $args   An array of additional arguments.
    109      */
    110     public function end_el( &$output, $object, $depth = 0, $args = array() ) {}
     106     * @param string $output      Used to append additional content (passed by reference).
     107     * @param object $data_object The data object.
     108     * @param int    $depth       Depth of the item.
     109     * @param array  $args        An array of additional arguments.
     110     */
     111    public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {}
    111112
    112113    /**
Note: See TracChangeset for help on using the changeset viewer.