Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 23 months ago

#55327 closed task (blessed) (fixed)

PHP 8.0: improvements to allow for named parameters in WP 6.0

Reported by: peterwilsoncc's profile peterwilsoncc Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: General Keywords: php80 has-patch has-unit-tests
Focuses: Cc:

Description

Follow up to #51553, quoted in full below:

PHP 8.0 introduces the ability to pass named parameters to function calls.
Ref: https://wiki.php.net/rfc/named_params

Code example:

<?php
// Using positional arguments:
array_fill(0, 100, 50);
 
// Using named arguments:
array_fill(start_index: 0, num: 100, value: 50);

// Named arguments do not have to follow the same order as positional arguments:
array_fill(value: 50, num: 100, start_index: 0);

More than anything, this means that, as of PHP 8.0, renaming a parameter in a function declaration is a backward-compatibility break!

This should most definitely get prominent mention in the PHP8 dev-note as a lot of Core/plugin/theme developers will not be aware of this at this time.

I'm opening this ticket to address a number of issues this brings up for WordPress Core.

I've so far identified three tasks which should be executed ASAP to prepare for named parameters in function calls.

Task 1: Review Function Signatures of methods in child classes

Methods in child classes may use different parameter names than those used for the same method by its parent. Similarly, classes implementing an interface do not have to use the same parameter names.

While this does not change in PHP 8, it could create problems when the method is called using named parameters.

To quote from the RFC:

If an inheriting class changes a parameter name, calls using named arguments might fail, thus violating the Liskov substitution principle (LSP).

PHP will silently accept parameter name changes during inheritance, which may result in call-time exceptions when methods with renamed parameters are called

Code sample:

<?php
interface I {
    public function test($foo, $bar);
}
 
class C implements I {
    public function test($a, $b) {}
}
 
$obj = new C;
 
// Pass params according to I::test() contract
$obj->test(foo: "foo", bar: "bar"); // ERROR!

Note: For variadic functions this will not cause an error, but will move the unrecognized names to be part of the variadic argument, which can cause all sorts of problems.
Code sample courtesy of Chris Riley illustrating the problem: https://3v4l.org/MhJ79

With regards to WordPress, I'd like to propose making the parameter names in child classes/classes implementing an interface consistent to prevent such issues.

Task 2: Review Other Function Signatures

  1. The function signatures of existing functions and methods of all WordPress code should be examined and non-descriptive parameter names should be fixed (renamed) NOW as later will no longer be an option without creating a BC-break.
  2. While using reserved keywords as parameter name labels is allowed, in the context of function calls using named parameters, this will easily lead to confusion. I'd like to recommend to rename function parameters which use reserved keywords to remove this confusion.
    <?php
    function array_foobar($toggle = false, $array = []) {}
    
    array_foobar(array: $value);
    

Task 3: Review all uses of call_user_func_array()

Named parameters cause a BC-break for call_user_func_array() when passing an associative array.
In previous PHP versions, the array keys would have been ignored. In PHP 8, string keys will be interpreted as parameter name labels.

For more detail, see: https://wiki.php.net/rfc/named_params#call_user_func_and_friends

Basically, we need to make sure that any array passed to call_user_func_array() does NOT have string keys. If it does or if the format of the array is unknown (like when it is passed in via a function parameter), we need to add extra safeguards to make the code cross-version compatible.
A typical way to do this would be to use array_values() on the array before passing it to call_user_func_array(), though beware that will break code written for PHP 8 which actually expects the label to be used.

Other references:

Related Trac tickets: #50913, #50531

Change History (70)

#1 @jrf
3 years ago

  • Keywords php80 added

#2 @SergeyBiryukov
3 years ago

In 52946:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-custom-image-header.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 $object variable in Custom_Image_Header class methods to $attachment for clarity and consistency, as the variable type is actually an array, and updates the documentation accordingly.

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

This ticket was mentioned in PR #2457 on WordPress/wordpress-develop by JustinyAhin.


3 years ago
#4

Related Trac ticket: https://core.trac.wordpress.org/ticket/55327.

This PR fixes some warning with reserved PHP names used as parameter.

#5 @SergeyBiryukov
3 years ago

In 52996:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-ftp.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 $string parameter of ftp_base::glob_pattern_match() to $subject.

Follow-up to [52946].

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

#6 @SergeyBiryukov
3 years ago

In 52997:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-plugin-upgrader.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 $return variable in Plugin_Upgrader class methods to $response and updates the documentation accordingly.

Follow-up to [47409], [52946], [52996].

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

#7 @SergeyBiryukov
3 years ago

In 52998:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-theme-upgrader.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 $return variable in Theme_Upgrader class methods to $response and updates the documentation accordingly.

Follow-up to [47409], [52946], [52996], [52997].

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

#8 @SergeyBiryukov
3 years ago

In 53003:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-debug-data.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 $var parameter to $mysql_var in WP_Debug_Data::get_mysql_var().

Additionally, $type is renamed to $data_type in WP_Debug_Data::format() for clarity.

Follow-up to [51522], [52946], [52996], [52997], [52998].

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

#9 @SergeyBiryukov
3 years ago

In 53014:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-filesystem-base.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 $echo parameter to $verbose in WP_Filesystem_Base::find_base_dir() and ::get_base_dir(), and updates the documentation accordingly. This matches the class property of the same name.

Follow-up to [52946], [52996], [52997], [52998], [53003].

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

#10 @SergeyBiryukov
3 years ago

In 53029:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-importer.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 $string parameter to $text in WP_Importer::min_whitespace().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014].

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

This ticket was mentioned in PR #2484 on WordPress/wordpress-develop by JustinyAhin.


3 years ago
#11

Related Trac ticket: https://core.trac.wordpress.org/ticket/55327.

This PR fixes some warning with reserved PHP names used as parameter.

See https://gist.github.com/jrfnl/a42f06ec032b0d7911cba32a72ea99ff.

#12 @SergeyBiryukov
3 years ago

In 53039:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-list-table.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 $default parameter to $default_value in WP_List_Table::get_items_per_page().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029].

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

#13 @SergeyBiryukov
3 years ago

In 53040:

Docs: Add missing descriptions for WP_List_Table::get_items_per_page() parameters.

Follow-up to [53039].

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

This ticket was mentioned in Slack in #core by costdev. View the logs.


3 years ago

This ticket was mentioned in PR #2530 on WordPress/wordpress-develop by JustinyAhin.


3 years ago
#15

Related Trac ticket: https://core.trac.wordpress.org/ticket/55327.

This PR fixes some warning with reserved PHP names used as parameter.

#16 @SergeyBiryukov
3 years ago

In 53116:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-posts-list-table.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 $class parameter to $css_class in WP_Posts_List_Table::get_edit_link().
  • Renames the $parent parameter to $parent_page in WP_Posts_List_Table::_page_rows().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039].

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

#17 @SergeyBiryukov
3 years ago

In 53117:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-site-health.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 $class parameter to $class_name in WP_Site_Health::test_php_extension_availability().
  • Renames some other parameters for consistency.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116].

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

#18 @SergeyBiryukov
3 years ago

In 53137:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-site-icon.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 $object variable to $attachment in WP_Site_Icon::insert_attachment() and updates the documentation accordingly.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117].

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

#19 @SergeyBiryukov
3 years ago

In 53174:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-wp-terms-list-table.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 $parent parameter to $parent_term in WP_Terms_List_Table::_rows().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137].

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

#21 @SergeyBiryukov
3 years ago

In 53183:

Coding Standards: Rename the $object variable to $attachment in several files.

This brings some consistency with a similar fragment in Custom_Image_Heade::step_2_manage_upload(), WP_Site_Icon::insert_attachment(), media_handle_upload(), and clarifies the type of the data.

Follow-up to [52946], [53137].

See #55327, #54728.

#22 @SergeyBiryukov
3 years ago

In 53184:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/deprecated.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 $default and $parent parameters to $default_category and $parent_category in dropdown_categories().
  • Renames the $default parameter to $default_link_category in dropdown_link_categories().
  • Renames the $parent parameter to $parent_cat and some other parameters for consistency in wp_dropdown_cats().
  • Renames the $function to $callback in add_object_page() and add_utility_page().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174].

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

SergeyBiryukov commented on PR #2427:


3 years ago
#23

All commits have been merged here.

#24 @SergeyBiryukov
3 years ago

In 53185:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/list-table.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 $class parameter to $class_name in _get_list_table().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184].

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

#25 @SergeyBiryukov
3 years ago

In 53192:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/media.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 $return parameter to $return_type in media_sideload_image().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185].

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

#26 @SergeyBiryukov
3 years ago

In 53193:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/menu.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 $class parameter to $classes in add_cssclass().
  • Renames the $add parameter to $class_to_add for clarity.
  • Includes minor code layout changes for better readability.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192].

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

#27 @SergeyBiryukov
3 years ago

In 53198:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/meta-boxes.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 $class parameter to $xfn_relationship in xfn_check().
  • Renames the $value parameter to $xfn_value for clarity.
  • Includes minor code layout changes for better readability.

Reference: XFN: Getting Started.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193].

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

#28 @SergeyBiryukov
3 years ago

In 53203:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/ms.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 $echo parameter to $display_message in upload_is_user_over_quota().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198].

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

#29 @SergeyBiryukov
3 years ago

In 53207:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/nav-menu.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 $echo parameter to $display in wp_nav_menu_disabled_check().
  • Renames the $object parameter to $item_object in:
    • wp_nav_menu_item_post_type_meta_box()
    • wp_nav_menu_item_taxonomy_meta_box()
    • _wp_nav_menu_meta_box_object()

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203].

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

#30 @SergeyBiryukov
3 years ago

In 53215:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/plugin.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 $function parameter to $callback in:
    • add_menu_page()
    • add_submenu_page()
    • add_management_page()
    • add_options_page()
    • add_theme_page()
    • add_plugins_page()
    • add_users_page()
    • add_dashboard_page()
    • add_posts_page()
    • add_media_page()
    • add_links_page()
    • add_pages_page()
    • add_comments_page()
  • Renames the $echo parameter to $display in menu_page_url().
  • Renames the $parent parameter to $parent_page in get_admin_page_parent().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207].

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

#31 @SergeyBiryukov
3 years ago

In 53216:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/taxonomy.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 $parent parameter to $category_parent in category_exists() and wp_create_category(). This matches the category object property of the same name.
  • Amends similar parameters in dropdown_categories() and wp_dropdown_cats() for consistency.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215].

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

#32 @SergeyBiryukov
3 years ago

In 53220:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/template.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 $echo parameter to $display in:
    • wp_popular_terms_checklist()
    • _post_states()
    • _media_states()
  • Renames the $default parameter to $default_term in wp_popular_terms_checklist().
  • Renames the $default parameter to $default_template in page_template_dropdown().
  • Renames the $default parameter to $default_page in parent_dropdown().
  • Renames the $object parameter to $data_object in:
    • do_block_editor_incompatible_meta_box()
    • do_meta_boxes()
    • do_accordion_sections()
  • Amends the $item_object parameter in other functions for consistency:
    • wp_nav_menu_item_post_type_meta_box()
    • wp_nav_menu_item_taxonomy_meta_box()
    • _wp_nav_menu_meta_box_object()

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216].

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

#33 @SergeyBiryukov
3 years ago

In 53222:

Menus: Use correct parameter in _wp_nav_menu_meta_box_object().

Follow-up to [53220].

Props davidbaumwald.
See #55327.

#34 @SergeyBiryukov
3 years ago

In 53230:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/upgrade.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 $public parameter to $is_public in wp_install().

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

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

#35 @SergeyBiryukov
3 years ago

In 53231:

Tests: Update the test for wp_install() signature.

Follow-up to [53230].

See #55327.

#36 @SergeyBiryukov
3 years ago

In 53232:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/install-helper.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 $default parameter to $default_value in check_column().

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

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

#37 @SergeyBiryukov
3 years ago

In 53236:

Code Modernization: Rename parameters that use reserved keywords in bundled themes.

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 $class parameter to $css_class in:
    • twentysixteen_excerpt()
    • twentynineteen_post_classes()
  • Renames the $echo parameter to $display in:
    • twentythirteen_entry_date()
    • twentytwenty_generate_css()
    • twentytwenty_site_logo()
    • twentytwenty_site_description()
    • twenty_twenty_one_generate_css()

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

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

SergeyBiryukov commented on PR #2457:


3 years ago
#38

Thanks for the PR! All commits from the second batch of changes have been merged.

#39 @SergeyBiryukov
3 years ago

In 53239:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/atomlib.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 $string parameter to $content in AtomParser::xml_escape().

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

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

#40 @SergeyBiryukov
3 years ago

In 53240:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/block-supports/border.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 $default parameter to $default_value in wp_has_border_feature_support().

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

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

#41 @peterwilsoncc
3 years ago

Given the need for [53222] after the breakage in [53220], I think commits on this ticket should cease after the WP 6.0 beta 3 release.

A follow up ticket can be created for WP 6.1.

#42 @SergeyBiryukov
3 years ago

In 53242:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-customize-manager.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 $default parameter to $default_value in WP_Customize_Manager::post_value().
  • Renames the $return parameter to $callback in WP_Customize_Manager::remove_preview_signature().

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

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

#43 @SergeyBiryukov
3 years ago

In 53243:

Code Modernization: Rename parameters that use reserved keywords in wp_die_*_handler filters.

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 $function parameter to $callback in wp_die_*_handler filters, which aims to make it easier to use a non-reserved parameter name for anyone utilizing these filters.

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

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

#44 @SergeyBiryukov
3 years ago

In 53245:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-customize-nav-menus.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 $type and $object parameters to $object_type and $object_name in WP_Customize_Nav_Menus::load_available_items_query().

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

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

#45 @SergeyBiryukov
3 years ago

In 53246:

Code Modernization: Rename parameters that use reserved keywords in swp-includes/class-wp-customize-setting.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 $default parameter to $default_value in WP_Customize_Setting class methods.

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

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

#46 @SergeyBiryukov
3 years ago

In 53257:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-customize-widgets.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 $default parameter to $default_value in WP_Customize_Widgets class methods.

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

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

#47 @SergeyBiryukov
3 years ago

In 53269:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-embed.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 $match parameter to $matches in WP_Embed::autoembed_callback().

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

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

#48 @SergeyBiryukov
3 years ago

In 53270:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-image-editor-gd.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 $function parameter to $callback in WP_Image_Editor_GD::make_image().

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

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

#49 @SergeyBiryukov
3 years ago

In 53271:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-image-editor.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 $function parameter to $callback in WP_Image_Editor::make_image().

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

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

#50 @SergeyBiryukov
3 years ago

In 53272:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-comment-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 $string parameter to $search in WP_Comment_Query::get_search_sql().

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

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

#51 @SergeyBiryukov
3 years ago

In 53273:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-network-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 $string parameter to $search in WP_Network_Query::get_search_sql().

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

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

#52 @SergeyBiryukov
3 years ago

In 53274:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-site-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 $string parameter to $search in WP_Site_Query::get_search_sql().

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

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

#53 @SergeyBiryukov
3 years ago

In 53275:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-term-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 $string parameter to $search in WP_Term_Query::get_search_sql().

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

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

#54 @SergeyBiryukov
3 years ago

In 53276:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-user-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 $string parameter to $search in WP_User_Query::get_search_sql().

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

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

#55 @SergeyBiryukov
3 years ago

In 53277:

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.

#56 @SergeyBiryukov
3 years ago

In 53281:

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 $list parameter to $status in WP_Dependencies::query().

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], [53277].

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

#57 @SergeyBiryukov
3 years ago

In 53283:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class.wp-scripts.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 $echo parameter to $display in WP_Scripts class methods.

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], [53277], [53281].

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

#58 @SergeyBiryukov
3 years ago

In 53284:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/class.wp-styles.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 $echo parameter to $display in WP_Styles class methods.

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], [53277], [53281], [53283].

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

#59 @SergeyBiryukov
3 years ago

In 53285:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/comment-template.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 $class parameter to $css_class in comment_class() and get_comment_class().
  • Renames the $echo parameter to $display in comment_class().

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], [53277], [53281], [53283], [53284].

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

#60 @SergeyBiryukov
3 years ago

In 53287:

Code Modernization: Rename parameters that use reserved keywords in wp-includes/deprecated.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 $echo parameter to $display in:
    • the_category_ID()
    • get_author_link()
    • get_links()
    • get_category_rss_link()
    • get_author_rss_link()
  • Renames the $string parameter to $text in wp_specialchars().
  • Renames the $string parameter to $message in debug_fwrite().
  • Renames the $string parameter to $content in wp_kses_js_entities().

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], [53277], [53281], [53283], [53284], [53285].

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

#61 follow-up: @SergeyBiryukov
3 years ago

Status overview:

  • PR #2427 and PR #2457 are committed.
  • PR #2484 is mostly committed, except for a few files that need a closer review to check whether the parameters there should be renamed or stay in line with the polyfilled functions, parent classes, etc.
    • wp-includes/class-json.php
    • wp-includes/class-wp-text-diff-renderer-inline.php
    • wp-includes/class-wp-text-diff-renderer-table.php
    • wp-includes/compat.php
  • PR #2530 and PR #2590 still need a review.

The remaining work can be moved to 6.1, per comment:41.

#62 in reply to: ↑ 61 @peterwilsoncc
3 years ago

Replying to SergeyBiryukov:

The remaining work can be moved to 6.1, per comment:41.

Thank you, I will leave you to create the follow up ticket.

I'll keep this open for now in case any bugs are picked up in commits made on this ticket.

This ticket was mentioned in PR #2642 on WordPress/wordpress-develop by JustinyAhin.


3 years ago
#63

  • Keywords has-unit-tests added

Related Trac ticket: https://core.trac.wordpress.org/ticket/55327.

This PR fixes some warning with reserved PHP names used as parameter.

#64 @SergeyBiryukov
3 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

#65 @SergeyBiryukov
3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

With 6.0 RC1 tomorrow, closing this as fixed for 6.0.

Created #55650 for the 6.1 cycle, let's continue there.

SergeyBiryukov commented on PR #2484:


3 years ago
#66

Thanks for the PR! Most of the commits have been merged in various changesets on tickets #55327 and #55650.

The remaining files are:

  • wp-includes/class-json.php
  • wp-includes/class-wp-text-diff-renderer-inline.php
  • wp-includes/class-wp-text-diff-renderer-table.php

The first one is a copy of the Services_JSON package, which used to be a PECL extension and has since been bundled and compiled into PHP by default. The parameters in this file should be the same as in the native PHP class.

The last two extend the Text_Diff_Renderer_inline and Text_Diff_Renderer classes from the Text_Diff package and should have the same parameters as the parent class methods, per the Task 1 section of ticket #51553.

So I think these three files don't need any changes at this time.

This ticket was mentioned in Slack in #core-php by jspellman. View the logs.


2 years ago

@SergeyBiryukov commented on PR #2530:


2 years ago
#68

Thanks for the PR! All commits from this batch of changes have been merged.

@SergeyBiryukov commented on PR #2590:


2 years ago
#69

Thanks for the PR! All commits from this batch of changes have been merged.

@SergeyBiryukov commented on PR #2642:


23 months ago
#70

Thanks for the PR! All commits from this batch of changes have been merged.

Note: See TracTickets for help on using tickets.