WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 5 weeks ago

#21865 closed enhancement (fixed)

Audit call time pass by reference usage

Reported by: wonderboymusic Owned by: ryan
Priority: normal Milestone: 3.5
Component: General Version:
Severity: normal Keywords: has-patch do-not-punt
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 9 months ago.

Download all attachments as: .zip

Change History (13)

comment:1 Amit_k9 months ago

Related #21839

comment:2 nacin9 months ago

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

comment:3 nacin9 months 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.

comment:5 ryan9 months ago

In [22114]:

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

comment:6 ryan9 months ago

Those are just the ones that issued an E_STRICT.

comment:7 ryan9 months ago

In [22115]:

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

comment:8 ryan9 months ago

In [22116]:

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

comment:9 ryan9 months ago

In [22117]:

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

comment:10 ryan9 months 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

comment:11 TobiasBg9 months 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.

comment:12 WraithKenny5 weeks ago

Yes you can drop the &

Note: See TracTickets for help on using tickets.