Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#21865 closed enhancement (fixed)

Audit call time pass by reference usage

Reported by: wonderboymusic's profile wonderboymusic Owned by: ryan's profile ryan
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch do-not-punt
Focuses: Cc:

Description

In PHP 4, it was necessary to use a reference to create a callback that points to the actual object, and not a copy of it. This is no longer the case.

Also, I found more instances of $var = &my_func();. I have not touched any instance of $var1 =&$var2;. All unit tests pass (minus Tests_Theme_WPTheme::test_wp_theme_uris_with_spaces which always fails).

Attachments (1)

call-time-pass-by.diff (19.0 KB) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (13)

#1 @Amit_k
12 years ago

Related #21839

#2 @nacin
12 years ago

  • Owner set to ryan
  • Status changed from new to assigned

#3 @nacin
12 years ago

  • Keywords do-not-punt added

Some of these may be necessary. For example, I don't think $term = &get_term() will work if get_term() returns null (rather than $null = null). get_term() wasn't changed to return a straight null in #21839, but others might have been.

#5 @ryan
12 years ago

In [22114]:

Avoid 'Only variables should be assigned by reference' warning. Props wonderboymusic. see #21865

#6 @ryan
12 years ago

Those are just the ones that issued an E_STRICT.

#7 @ryan
12 years ago

In [22115]:

Avoid 'Only variables should be assigned by reference' warning. Props wonderboymusic. see #21865

#8 @ryan
12 years ago

In [22116]:

Avoid 'Only variables should be assigned by reference' warning. Props wonderboymusic. see #21865

#9 @ryan
12 years ago

In [22117]:

Avoid 'Only variables should be assigned by reference' warning. Props wonderboymusic. see #21865

#10 @ryan
12 years ago

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

In [22118]:

Objects no longer need to be explicitly passed by ref to call_user_func*() to be callable. Props wonderboymusic. fixes #21865

#11 @TobiasBg
12 years ago

So does this mean that it is now pretty much safe to replace all array( &$this, '...' ) in an add_filter or add_action call in a plugin (that uses a class) with array( $this, '...' )?
Are there reasons not to do this?

I'm asking, because when doing a quick grep through code, I still saw quite a few array( &$this, '...' ) in add_filter or add_action calls not being changed. And as this ticket was closed, they likely won't be.

#12 @WraithKenny
12 years ago

Yes you can drop the &

Note: See TracTickets for help on using tickets.