[wp-trac] [WordPress Trac] #25160: Unnecessarily passing $this by reference in core (was: Unnecessarily passing object by reference in WP_Widget::form_callback())
WordPress Trac
noreply at wordpress.org
Wed Aug 28 14:37:22 UTC 2013
#25160: Unnecessarily passing $this by reference in core
-------------------------------------+------------------------------
Reporter: jdgrimes | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: trivial | Resolution:
Keywords: has-patch needs-testing |
-------------------------------------+------------------------------
Changes (by jdgrimes):
* keywords: has-patch => has-patch needs-testing
* component: Widgets => General
Comment:
That patch is a first attempt at ripping out all instances of `&$this`. It
removes many unnecesary uses of `apply_filters_ref_array()` and
`do_action_ref_array()` as a result of this as well. There is actually one
place that requires passing `$this` by reference, which is the
`wp_default_scripts` action, called in [/browser/trunk/wp-includes/class
.wp-scripts.php#L39].
This patch currently covers all of the WordPress package, in `/src`,
`/tests` and `/tools`. It does not cover other included libraries.
There are several cases where objects other than `$this` were being passed
by reference unnecessarily within the files covered, and I have removed
those as well. However, I didn't touch any of the files where `$this` is
not passed by reference, so there may be objects passing by reference
unnecessarily in them.
A list of files covered by this patch:
{{{
./src/wp-admin/custom-background.php
./src/wp-admin/custom-header.php
./src/wp-admin/includes/class-wp-importer.php
./src/wp-admin/includes/class-wp-list-table.php
./src/wp-admin/includes/class-wp-ms-themes-list-table.php
./src/wp-admin/includes/class-wp-plugins-list-table.php
./src/wp-admin/includes/class-wp-upgrader.php
./src/wp-admin/includes/deprecated.php
./src/wp-admin/includes/list-table.php
./src/wp-includes/class-wp.php
./src/wp-includes/class.wp-scripts.php
./src/wp-includes/class.wp-styles.php
./src/wp-includes/comment.php
./src/wp-includes/plugin.php
./src/wp-includes/query.php
./src/wp-includes/rewrite.php
./src/wp-includes/user.php
./src/wp-includes/widgets.php
./tests/includes/utils.php
./tests/includes/wp-profiler.php
./tests/tests/admin/includesTheme.php
./tests/tests/filters.php
./tests/tests/meta.php
./tests/tests/theme/themeDir.php
./tests/tests/theme/WPTheme.php
./tests/tests/user/capabilities.php
./tools/i18n/makepot.php
./tools/i18n/not-gettexted.php
./tools/i18n/pot-ext-meta.php
./tools/i18n/t/NotGettextedTest.php
}}}
Files which contain `&$this`, but which aren't included (yet):
{{{
./src/wp-content/themes/twentyeleven/inc/widgets.php
./src/wp-includes/atomlib.php
./src/wp-includes/class-simplepie.php
./src/wp-includes/ID3/module.audio-video.asf.php
./src/wp-includes/ID3/module.audio-video.flv.php
./src/wp-includes/ID3/module.audio-video.matroska.php
./src/wp-includes/ID3/module.audio-video.quicktime.php
./src/wp-includes/ID3/module.audio-video.riff.php
./src/wp-includes/ID3/module.audio.ac3.php
./src/wp-includes/ID3/module.audio.dts.php
./src/wp-includes/ID3/module.audio.flac.php
./src/wp-includes/ID3/module.audio.mp3.php
./src/wp-includes/ID3/module.audio.ogg.php
./src/wp-includes/ID3/module.tag.apetag.php
./src/wp-includes/ID3/module.tag.id3v1.php
./src/wp-includes/ID3/module.tag.id3v2.php
./src/wp-includes/ID3/module.tag.lyrics3.php
./src/wp-includes/pomo/mo.php
./src/wp-includes/Text/Diff/Renderer/inline.php
./src/wp-includes/Text/Diff.php
./tests/data/plugins/wordpress-importer/parsers.php
./tests/data/plugins/wordpress-importer/wordpress-importer.php
}}}
This patch needs testing to make sure nothing is broken. I just ran the
whole tests suite, and there seems to be some issues with all of the tests
run by `tests/tests/query/conditionals.php`. I don't know if this is
related to this patch (I failed to run the tests before applying it).
On a side note, while doing this I noticed that the tests for
`apply_filters_ref_array()` may need to be revised - they are passing an
object by reference.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25160#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list