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
This commit is contained in:
hellofromTonya 2021-09-09 13:03:55 +00:00
parent 7abc752329
commit a395d4c50e
7 changed files with 44 additions and 33 deletions

View File

@ -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 .= "</li>\n";
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 = '';

View File

@ -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";

View File

@ -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.

View File

@ -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.