[wp-trac] [WordPress Trac] #41525: Remove usage of each() from WP_PHPUnit_Util_Getopt

WordPress Trac noreply at wordpress.org
Tue Aug 1 23:56:04 UTC 2017


#41525: Remove usage of each() from WP_PHPUnit_Util_Getopt
------------------------------+-------------------------
 Reporter:  johnbillion       |      Owner:
     Type:  task (blessed)    |     Status:  new
 Priority:  normal            |  Milestone:  4.9
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:  needs-patch
  Focuses:                    |
------------------------------+-------------------------
 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()`:

 1. 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.
 2. 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''
 ([https://github.com/sebastianbergmann/phpunit/blob/a3b2fc068fdf4f9392da1fffec3782e3454bf971/src/Util/Getopt.php#L107-L107
 ref]), whereupon its array cursor is moved on
 ([https://github.com/sebastianbergmann/phpunit/blob/a3b2fc068fdf4f9392da1fffec3782e3454bf971/src/Util/Getopt.php#L140-L145
 ref]) under some condition.

 This mess needs to be fixed.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41525>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list