Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 23 months ago

#16752 closed enhancement (wontfix)

Remove unnecessary return by reference

Reported by: scribu Owned by:
Milestone: Priority: low
Severity: normal Version:
Component: General Keywords: php5 has-patch needs-testing
Focuses: Cc:


There are several functions in WP that return an object by reference.

With PHP5, this is not necessary anymore.

Examples of such functions: get_post(), get_term().

Attachments (3)

16752.patch (1.5 KB) - added by hakre 3 years ago.
16752-2.diff (575 bytes) - added by jkudish 3 years ago.
better return for get_term
16752-3.diff (1.1 KB) - added by jkudish 3 years ago.
better returns for get_term and get_post

Download all attachments as: .zip

Change History (10)

comment:1 hakre3 years ago

I don't know how much the trade-off is for that, but the PHP manual states the following:

Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so.

I think in PHP 4 code it was returned by reference for memory reasons. We should not do that any longer because we don't need it.

Related: #16661, #16813, #16917

Version 1, edited 3 years ago by hakre (previous) (next) (diff)

hakre3 years ago

comment:2 hakre3 years ago

16752.patch as an example. This private function did return by reference, but the callee never received as reference. That's fixed.

The patch additionally shows that it's now possible to call object methods on function returns.

jkudish3 years ago

better return for get_term

jkudish3 years ago

better returns for get_term and get_post

comment:3 jkudish3 years ago

  • Cc joachim.kudish@… added
  • Keywords has-patch needs-testing added; needs-patch removed

comment:4 scribu3 years ago

  • Keywords 3.2-early removed

comment:5 scribu3 years ago

  • Priority changed from normal to low

comment:6 scribu2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This has been shown to create back-compat problems.

comment:7 jkudish23 months ago

removed for get_post in [21597]

Note: See TracTickets for help on using tickets.