Fix: PHP 8.0 named parameters compatibility#11528
Fix: PHP 8.0 named parameters compatibility#11528vidushigupta0607 wants to merge 1 commit intoWordPress:trunkfrom
Conversation
97f38b9 to
c6d9646
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Task 1: Fix reserved keyword parameter names in Core - Rename wp_is_valid_utf8() fallback branch parameter from $string to $bytes (utf8.php:51) to match the primary branch and ensure consistency for PHP 8.0+ named argument callers. Task 2: Align child class parameter names with abstract parent signatures - Rename prepare_item_for_response() first parameter to $item in child controllers to match WP_REST_Controller::prepare_item_for_response($item): class-wp-rest-abilities-v1-categories-controller.php ($category → $item), class-wp-rest-abilities-v1-list-controller.php ($ability → $item), class-wp-rest-global-styles-controller.php ($post → $item), class-wp-rest-global-styles-revisions-controller.php ($post → $item), class-wp-rest-menus-controller.php ($term → $item). Task 3: Audit and wrap call_user_func_array() usage in Core - Introduce wp_normalize_call_user_func_args() in load.php to strip string keys from argument arrays before they reach call_user_func_array(), preventing PHP 8.0+ from misinterpreting them as named arguments. - Wrap dynamic callback calls where $args could contain non-integer keys: class-wp-hook.php, class-wp-customize-widgets.php, class-wp-image-editor.php, class-wp-rest-widgets-controller.php, functions.php, widgets.php, and wp-admin dispatch sites (ajax-actions, class-wp-screen, dashboard, media, post, widgets, widgets-form). - Add a safety comment to class-wp-block-bindings-source.php:86 documenting why its call_user_func_array() does not need wrapping. Task 4: Escalate PHPCS rule to error severity - Update phpcs.xml.dist to escalate Universal.NamingConventions.NoReservedKeywordParameterNames from warning to error, preventing future reserved keyword parameter names (string, list, array, etc.) that break PHP 8.0+ named argument syntax. See: https://core.trac.wordpress.org/ticket/59649
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
4c71786 to
9a6f484
Compare
Problem
PHP 8.0 introduced named arguments (func(param: $value)), which creates compatibility risks for WordPress Core:
Root Cause
WordPress Core had no systematic audit or enforcement of PHP 8.0 named parameter compatibility. While wp_normalize_call_user_func_args() existed (introduced in WP 7.0), its usage was inconsistent, and reserved keyword parameter names were not actively prevented.
Solution
Example Usage
Before: Function calls with reserved keyword parameter names would fail under PHP 8.0 named arguments
After: Parameter names are non-reserved and compatible
Impact
This change ensures WordPress Core is compatible with PHP 8.0+ named argument syntax across all actively maintained code. The implementation:
Trac Link
https://core.trac.wordpress.org/ticket/59649