From a395d4c50e5acba36bad7d97043e292fbb4a1832 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Thu, 9 Sep 2021 13:03:55 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@51780 git-svn-id: http://core.svn.wordpress.org/trunk@51387 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-walker-category-checklist.php | 11 ++++++----- wp-includes/class-walker-category.php | 13 +++++++------ wp-includes/class-walker-comment.php | 18 ++++++++++++------ wp-includes/class-walker-nav-menu.php | 11 ++++++----- wp-includes/class-walker-page.php | 11 ++++++----- wp-includes/class-wp-walker.php | 11 ++++++----- wp-includes/version.php | 2 +- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/wp-admin/includes/class-walker-category-checklist.php b/wp-admin/includes/class-walker-category-checklist.php index 90ee40f834..b86ba23a2b 100644 --- a/wp-admin/includes/class-walker-category-checklist.php +++ b/wp-admin/includes/class-walker-category-checklist.php @@ -125,13 +125,14 @@ class Walker_Category_Checklist extends Walker { * @see Walker::end_el() * * @since 2.5.1 + * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support. * - * @param string $output Used to append additional content (passed by reference). - * @param WP_Term $category The current term object. - * @param int $depth Depth of the term in reference to parents. Default 0. - * @param array $args An array of arguments. @see wp_terms_checklist() + * @param string $output Used to append additional content (passed by reference). + * @param WP_Term $data_object The current term object. + * @param int $depth Depth of the term in reference to parents. Default 0. + * @param array $args An array of arguments. @see wp_terms_checklist() */ - public function end_el( &$output, $category, $depth = 0, $args = array() ) { + public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { $output .= "\n"; } } diff --git a/wp-includes/class-walker-category.php b/wp-includes/class-walker-category.php index 43bb7c69cf..fcf54a333f 100644 --- a/wp-includes/class-walker-category.php +++ b/wp-includes/class-walker-category.php @@ -254,16 +254,17 @@ class Walker_Category extends Walker { * Ends the element output, if needed. * * @since 2.1.0 + * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support. * * @see Walker::end_el() * - * @param string $output Used to append additional content (passed by reference). - * @param object $page Not used. - * @param int $depth Optional. Depth of category. Not used. - * @param array $args Optional. An array of arguments. Only uses 'list' for whether should append - * to output. See wp_list_categories(). Default empty array. + * @param string $output Used to append additional content (passed by reference). + * @param object $data_object Category data object. Not used. + * @param int $depth Optional. Depth of category. Not used. + * @param array $args Optional. An array of arguments. Only uses 'list' for whether should + * append to output. See wp_list_categories(). Default empty array. */ - public function end_el( &$output, $page, $depth = 0, $args = array() ) { + public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { if ( 'list' !== $args['style'] ) { return; } diff --git a/wp-includes/class-walker-comment.php b/wp-includes/class-walker-comment.php index bf00996028..1a81a0b5d1 100644 --- a/wp-includes/class-walker-comment.php +++ b/wp-includes/class-walker-comment.php @@ -213,19 +213,25 @@ class Walker_Comment extends Walker { * Ends the element output, if needed. * * @since 2.7.0 + * @since 5.9.0 Renamed `$comment` to `$data_object` to match parent class for PHP 8 named parameter support. * * @see Walker::end_el() * @see wp_list_comments() * - * @param string $output Used to append additional content. Passed by reference. - * @param WP_Comment $comment The current comment object. Default current comment. - * @param int $depth Optional. Depth of the current comment. Default 0. - * @param array $args Optional. An array of arguments. Default empty array. + * @param string $output Used to append additional content. Passed by reference. + * @param WP_Comment $data_object Comment data object. + * @param int $depth Optional. Depth of the current comment. Default 0. + * @param array $args Optional. An array of arguments. Default empty array. */ - public function end_el( &$output, $comment, $depth = 0, $args = array() ) { + public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { if ( ! empty( $args['end-callback'] ) ) { ob_start(); - call_user_func( $args['end-callback'], $comment, $args, $depth ); + call_user_func( + $args['end-callback'], + $data_object, // The current comment object. + $args, + $depth + ); $output .= ob_get_clean(); return; } diff --git a/wp-includes/class-walker-nav-menu.php b/wp-includes/class-walker-nav-menu.php index 3fdc8d8c4b..fad796005c 100644 --- a/wp-includes/class-walker-nav-menu.php +++ b/wp-includes/class-walker-nav-menu.php @@ -256,15 +256,16 @@ class Walker_Nav_Menu extends Walker { * Ends the element output, if needed. * * @since 3.0.0 + * @since 5.9.0 Renamed `$item` to `$data_object` to match parent class for PHP 8 named parameter support. * * @see Walker::end_el() * - * @param string $output Used to append additional content (passed by reference). - * @param WP_Post $item Page data object. Not used. - * @param int $depth Depth of page. Not Used. - * @param stdClass $args An object of wp_nav_menu() arguments. + * @param string $output Used to append additional content (passed by reference). + * @param WP_Post $data_object Menu item data object. Not used. + * @param int $depth Depth of page. Not Used. + * @param stdClass $args An object of wp_nav_menu() arguments. */ - public function end_el( &$output, $item, $depth = 0, $args = null ) { + public function end_el( &$output, $data_object, $depth = 0, $args = null ) { if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; diff --git a/wp-includes/class-walker-page.php b/wp-includes/class-walker-page.php index daa162d74b..ad443dc2a6 100644 --- a/wp-includes/class-walker-page.php +++ b/wp-includes/class-walker-page.php @@ -222,15 +222,16 @@ class Walker_Page extends Walker { * Outputs the end of the current element in the tree. * * @since 2.1.0 + * @since 5.9.0 Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support. * * @see Walker::end_el() * - * @param string $output Used to append additional content. Passed by reference. - * @param WP_Post $page Page data object. Not used. - * @param int $depth Optional. Depth of page. Default 0 (unused). - * @param array $args Optional. Array of arguments. Default empty array. + * @param string $output Used to append additional content. Passed by reference. + * @param WP_Post $data_object Page data object. Not used. + * @param int $depth Optional. Depth of page. Default 0 (unused). + * @param array $args Optional. Array of arguments. Default empty array. */ - public function end_el( &$output, $page, $depth = 0, $args = array() ) { + public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; diff --git a/wp-includes/class-wp-walker.php b/wp-includes/class-wp-walker.php index 9e39777579..b50c2d7505 100644 --- a/wp-includes/class-wp-walker.php +++ b/wp-includes/class-wp-walker.php @@ -100,14 +100,15 @@ class Walker { * The $args parameter holds additional values that may be used with the child class methods. * * @since 2.1.0 + * @since 5.9.0 Renamed `$object` (a PHP reserved keyword) to `$data_object` for PHP 8 named parameter support. * @abstract * - * @param string $output Used to append additional content (passed by reference). - * @param object $object The data object. - * @param int $depth Depth of the item. - * @param array $args An array of additional arguments. + * @param string $output Used to append additional content (passed by reference). + * @param object $data_object The data object. + * @param int $depth Depth of the item. + * @param array $args An array of additional arguments. */ - public function end_el( &$output, $object, $depth = 0, $args = array() ) {} + public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {} /** * Traverse elements to create list from elements. diff --git a/wp-includes/version.php b/wp-includes/version.php index eafa858ba8..cf8a23499f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51779'; +$wp_version = '5.9-alpha-51780'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.