Opened 14 years ago
Closed 13 years ago
#17111 closed enhancement (wontfix)
Remove unnecessary copy-by-reference in do_action()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Performance | Keywords: | has-patch |
Focuses: | Cc: |
Description
There's this weird check in do_action():
if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this) $args[] =& $arg[0];
It was introduced in [4177], probably to fix PHP4 nastiness.
But, since we're on PHP5 now, the copy-by-reference is not needed anymore.
Attachments (3)
Change History (12)
#3
@
14 years ago
unlikely that plugins call do_action( 'whatever', array( &$this ) );
If memory serves, that unlikely call used to be an documented best practice a few years back.
#5
@
14 years ago
I've seen do_action( 'whatever', &$this );
but not do_action( 'something', array( &$this ) );
:
If a plugin somewhere does pass array( &$this )
, how bad would things break?
#6
in reply to:
↑ 4
@
14 years ago
Replying to scribu:
Link, or it didn't happen. :)
Sorry, not in much of a drive to google.com/archive.org the reference. FWIW, though, I vaguely recall seeing as an example of good things to do in the codex somewhere between 2005 and 2006. Plus, in case memory serves me wrong, that was the only means of getting the expected behavior (with php4 objects) back then anyway.
I'm arguably biased in some sense, since my own plugins called things that way back then. (Those versions are completely obsolete, so I don't care much; but pointing out why I'm raising the issue.)
This probably may no longer be a necessity with php5 objects (since that is what the array with a reference was all about)... But the rational behind the original behavior shouldn't be forgotten. And I dare suggest that a few test cases might be needed before things do change.
#7
@
14 years ago
The reason I'm skeptical is because do_action_ref_array() was also introduced in WP 2.1, when this change was made.
Eric & Denis: for a simple testcase, see test-do-action.php.
It basically transformed:
into
for the callback hooked to that action.
conservative.17111.diff simply removes the reference.
17111.diff removes the check entirely. Reasons:
do_action( 'whatever', array( &$this ) );