Opened 8 months ago
Last modified 5 days ago
#64643 new defect (bug)
Remove some obsolete return by refs
| Reported by: | swissspidy | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | coding-standards |
Description
[21792] / #21839 removed some unnecessary return by reference usage in core. However, it did not properly remove the ampersands from the function signatures.
For example, the signature of wp_get_post_revision is still function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ), which messes with static analysis.
I suggest auditing the usage, starting with the functions touched by that commit, and removing the ampersands where possible.
Change History (12)
This ticket was mentioned in PR #10941 on WordPress/wordpress-develop by @niravsherasiya7707.
8 months ago
#1
- Keywords has-patch added; needs-patch removed
@westonruter commented on PR #10941:
8 months ago
#3
Take it or leave it, but Gemini CLI found some additional possibilities:
-
src/wp-admin/includes/class-wp-upgrader-skin.php
diff --git a/src/wp-admin/includes/class-wp-upgrader-skin.php b/src/wp-admin/includes/class-wp-upgrader-skin.php index 831da3aeba..4c1615cdd2 100644
a b class WP_Upgrader_Skin { 83 83 * 84 84 * @param WP_Upgrader $upgrader 85 85 */ 86 public function set_upgrader( &$upgrader ) {86 public function set_upgrader( $upgrader ) { 87 87 if ( is_object( $upgrader ) ) { 88 $this->upgrader = &$upgrader;88 $this->upgrader = $upgrader; 89 89 } 90 90 $this->add_strings(); 91 91 } -
src/wp-includes/class-wp-hook.php
diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php index cd6860c0f8..cf6f5aeaca 100644
a b final class WP_Hook implements Iterator, ArrayAccess { 375 375 * 376 376 * @since 4.7.0 377 377 * 378 * @param array $args Arguments to pass to the hook callbacks. Passed by reference.378 * @param array $args Arguments to pass to the hook callbacks. 379 379 */ 380 public function do_all_hook( &$args ) {380 public function do_all_hook( $args ) { 381 381 $nesting_level = $this->nesting_level++; 382 382 $this->iterations[ $nesting_level ] = $this->priorities; 383 383 -
src/wp-includes/deprecated.php
diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 390d632492..897b1a48a3 100644
a b function get_theme_data( $theme_file ) { 3111 3111 * 3112 3112 * @param array $pages list of page objects 3113 3113 */ 3114 function update_page_cache( &$pages ) {3114 function update_page_cache( $pages ) { 3115 3115 _deprecated_function( __FUNCTION__, '3.4.0', 'update_post_cache()' ); 3116 3116 3117 3117 update_post_cache( $pages ); … … function sticky_class( $post_id = null ) { 3177 3177 * @deprecated 3.5.0 Use get_post_ancestors() 3178 3178 * @see get_post_ancestors() 3179 3179 * 3180 * @param WP_Post $post Post object , passed by reference(unused).3180 * @param WP_Post $post Post object (unused). 3181 3181 */ 3182 function _get_post_ancestors( &$post ) {3182 function _get_post_ancestors( $post ) { 3183 3183 _deprecated_function( __FUNCTION__, '3.5.0' ); 3184 3184 } 3185 3185 -
src/wp-includes/nav-menu-template.php
diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php index d90fdfa806..29d8a03944 100644
a b function wp_nav_menu( $args = array() ) { 324 324 * 325 325 * @param array $menu_items The current menu item objects to which to add the class property information. 326 326 */ 327 function _wp_menu_item_classes_by_context( &$menu_items ) {327 function _wp_menu_item_classes_by_context( $menu_items ) { 328 328 global $wp_query, $wp_rewrite; 329 329 330 330 $queried_object = $wp_query->get_queried_object(); -
src/wp-includes/pomo/entry.php
diff --git a/src/wp-includes/pomo/entry.php b/src/wp-includes/pomo/entry.php index e1b1c8f8c8..48c52384b1 100644
a b if ( ! class_exists( 'Translation_Entry', false ) ) : 114 114 * 115 115 * @param Translation_Entry $other Other translation entry. 116 116 */ 117 public function merge_with( &$other ) {117 public function merge_with( $other ) { 118 118 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); 119 119 $this->references = array_unique( array_merge( $this->references, $other->references ) ); 120 120 if ( $this->extracted_comments !== $other->extracted_comments ) { -
src/wp-includes/pomo/po.php
diff --git a/src/wp-includes/pomo/po.php b/src/wp-includes/pomo/po.php index de1bc92064..594ad80f4e 100644
a b if ( ! class_exists( 'PO', false ) ) : 486 486 * @param Translation_Entry $entry 487 487 * @param string $po_comment_line 488 488 */ 489 public function add_comment_to_entry( &$entry, $po_comment_line ) {489 public function add_comment_to_entry( $entry, $po_comment_line ) { 490 490 $first_two = substr( $po_comment_line, 0, 2 ); 491 491 $comment = trim( substr( $po_comment_line, 2 ) ); 492 492 if ( '#:' === $first_two ) { -
src/wp-includes/pomo/translations.php
diff --git a/src/wp-includes/pomo/translations.php b/src/wp-includes/pomo/translations.php index c4a9ba72d6..8d1a2183b9 100644
a b if ( ! class_exists( 'Translations', false ) ) : 130 130 * @param Translation_Entry $entry Translation entry. 131 131 * @return Translation_Entry|false Translation entry if it exists, false otherwise. 132 132 */ 133 public function translate_entry( &$entry ) {133 public function translate_entry( $entry ) { 134 134 $key = $entry->key(); 135 135 return $this->entries[ $key ] ?? false; 136 136 } … … if ( ! class_exists( 'Translations', false ) ) : 220 220 * 221 221 * @since 2.8.0 222 222 * 223 * @param Translations $other Another Translation object, whose translations will be merged in this one (passed by reference).223 * @param Translations $other Another Translation object, whose translations will be merged in this one. 224 224 */ 225 public function merge_with( &$other ) {225 public function merge_with( $other ) { 226 226 foreach ( $other->entries as $entry ) { 227 227 $this->entries[ $entry->key() ] = $entry; 228 228 } … … if ( ! class_exists( 'Translations', false ) ) : 235 235 * 236 236 * @param Translations $other 237 237 */ 238 public function merge_originals_with( &$other ) {238 public function merge_originals_with( $other ) { 239 239 foreach ( $other->entries as $entry ) { 240 240 if ( ! isset( $this->entries[ $entry->key() ] ) ) { 241 241 $this->entries[ $entry->key() ] = $entry; -
src/wp-includes/post.php
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index f4b06958e0..cb7a91d56c 100644
a b function get_page_hierarchy( $pages, $page_id = 0 ) { 6309 6309 * @see _page_traverse_name() 6310 6310 * 6311 6311 * @param int $page_id Page ID. 6312 * @param array $children Parent-children relations (passed by reference).6312 * @param array $children Parent-children relations. 6313 6313 * @param string[] $result Array of page names keyed by ID (passed by reference). 6314 6314 */ 6315 function _page_traverse_name( $page_id, &$children, &$result ) {6315 function _page_traverse_name( $page_id, $children, &$result ) { 6316 6316 if ( isset( $children[ $page_id ] ) ) { 6317 6317 foreach ( (array) $children[ $page_id ] as $child ) { 6318 6318 $result[ $child->ID ] = $child->post_name; … … function _get_last_post_time( $timezone, $field, $post_type = 'any' ) { 7678 7678 * 7679 7679 * @since 1.5.1 7680 7680 * 7681 * @param WP_Post[] $posts Array of post objects (passed by reference).7681 * @param WP_Post[] $posts Array of post objects. 7682 7682 */ 7683 function update_post_cache( &$posts ) {7683 function update_post_cache( $posts ) { 7684 7684 if ( ! $posts ) { 7685 7685 return; 7686 7686 } … … function clean_post_cache( $post ) { 7762 7762 * 7763 7763 * @since 1.5.0 7764 7764 * 7765 * @param WP_Post[] $posts Array of post objects (passed by reference).7765 * @param WP_Post[] $posts Array of post objects. 7766 7766 * @param string $post_type Optional. Post type. Default 'post'. 7767 7767 * @param bool $update_term_cache Optional. Whether to update the term cache. Default true. 7768 7768 * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. 7769 7769 */ 7770 function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {7770 function update_post_caches( $posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) { 7771 7771 // No point in doing all this work if we didn't match any posts. 7772 7772 if ( ! $posts ) { 7773 7773 return;
@niravsherasiya7707 commented on PR #10941:
8 months ago
#4
@westonruter Thanks, I have a plan to remove the ref passed parameter in phase-wise, based on the ticket. I have started with the changes done on mentioed changeset. Next, plan to scan the whole core codebase.
@niravsherasiya7707 commented on PR #10941:
8 months ago
#5
Note: E2E tests are failing for all the latest PRs.
#6
@
7 months ago
- Milestone 7.0 → 7.1
With 7.0 RC1 due out in the next few hours, this one needs to be punted. If someone is able to shepherd it in before then, feel free to move it back.
This ticket was mentioned in Slack in #core by adrianduffell. View the logs.
2 months ago
#9
@
2 months ago
This was discussed in today’s bug scrub. It's possible this could land in the short time remaining before RC 1. Does anyone have the bandwidth to review the PR?
#10
@
2 months ago
- Milestone 7.1 → 7.2
According to the Copilot review, PR 10941 appears to contain several backward-incompatible changes, and the points raised seem valid. I believe there is a risk in proceeding with this ticket right before RC1. If we are going to allow breaking changes, we should at least publish a dev note.
To allow more time for investigation, I'd like to punt this to 7.2.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Core ticket: https://core.trac.wordpress.org/ticket/64643