[wp-trac] [WordPress Trac] #41526: Remove usage of each() from Text_Diff_Engine_native
WordPress Trac
noreply at wordpress.org
Wed Aug 2 00:14:27 UTC 2017
#41526: Remove usage of each() from Text_Diff_Engine_native
--------------------------------+------------------------------------------
Reporter: johnbillion | Owner:
Type: task (blessed) | Status: new
Priority: normal | Milestone: 4.9
Component: External Libraries | Version:
Severity: normal | Keywords: needs-patch needs-unit-tests
Focuses: |
--------------------------------+------------------------------------------
Ticket split out from #40109.
`Text_Diff_Engine_native::_diag()` 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.
----
`Text_Diff_Engine_native::_diag()` iterates over `$matches` with `each()`
until the condition which causes the `break` clause is met, upon which the
second call to `each()` continues iteration from the same point in the
array. Lovely.
The `Text_Diff` library is a complex, third-party script with no test
coverage, so changes here need to be made carefully. Unit tests probably
could be introduced to demonstrate no regressions when `each()` is
replaced.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41526>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list