#41524 closed task (blessed) (fixed)
Remove usage of each() from WP_Upgrader
Reported by: | johnbillion | Owned by: | dd32 |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | major | Version: | |
Component: | Upgrade/Install | Keywords: | has-patch needs-testing needs-unit-tests |
Focuses: | Cc: |
Description
Ticket split out from #40109.
WP_Upgrader::clear_destination()
uses each()
, which is deprecated in PHP 7.2 and therefore should be removed.
The each()
function exhibits two pieces of behaviour which mean it can't simply be replaced with foreach()
:
- After
each()
has executed, the array cursor will be left on the next element of the array, or past the last element if it hits the end of the array. This means you can break out of an each loop, and continue the iteration at a later point.Text_Diff_Engine_native::_diag()
does just this. - With the
while ( each( $array ) )
pattern, it's possible to alter the elements in the array during iteration.WP_Upgrader::clear_destination()
does this.
Attachments (2)
Change History (11)
#3
@
7 years ago
Actually, I'm going to wager that this does not work, because the intention of the original code was to append items to $_files
during iteration, so that they too are iterated over.
Kill me.
#4
@
7 years ago
I added a recursive version of flattening the files from $wp_filesystem->dirlist()
. I'm not 100% certain on rules for private or underscore naming for internal functions.
I'd add a test but I'm honestly not sure where to start because as far as I can tell there's no tests on the WP_Upgrader
class.
This ticket was mentioned in Slack in #core by cjhaas. View the logs.
7 years ago
#6
@
7 years ago
- Owner set to dd32
- Resolution set to fixed
- Status changed from new to closed
In 41821:
#7
@
7 years ago
Thanks for the patch @chris@…, I simplified it a little bit and removed the usage of passed references to simplify the code a little.
There currently isn't any unit testing of the upgrade functionalities, I've skipped including one as I'm not sure of the best method on how to do that either.
This needs testing and, ideally, unit test coverage. Suggestions welcome.