#41525 closed task (blessed) (fixed)
Remove usage of each() from WP_PHPUnit_Util_Getopt
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Ticket split out from #40109.
WP_PHPUnit_Util_Getopt::__construct()
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_PHPUnit_Util_Getopt::__construct()
does just this, but in a very non-obvious manner. $argv
is passed into PHPUnit_Util_Getopt::parseLongOption()
as a reference (ref), whereupon its array cursor is moved on (ref) under some condition.
This mess needs to be fixed.
Attachments (1)
Change History (8)
#2
@
8 years ago
The \WP_PHPUnit_Util_Getopt
class is hard to test because it modifies some static variables. However, I took a try to get rid of the each() call.
The $i
variable was not used. We still keep the while()
pattern because it needs to be modified. However, instead of using each()
to fetch and advance the array iterator, this patch proposes to do it in separate calls. The immediately following next()
call advances the array pointer, making the while()
loop finish.
#41530 was marked as a duplicate.