[wp-trac] [WordPress Trac] #44543: PHP 7.3 compatibility: using `continue` in `switch` statements

WordPress Trac noreply at wordpress.org
Sun Jul 8 21:46:40 UTC 2018


#44543: PHP 7.3 compatibility: using `continue` in `switch` statements
--------------------------+-----------------------------------
 Reporter:  jrf           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:  2nd-opinion has-patch
  Focuses:                |
--------------------------+-----------------------------------
 As of PHP 7.3, using `continue` to target a `switch` control structure
 will throw an `E_WARNING`.

 Applying `continue` to a `switch` is equivalent to using `break` and quite
 possibly, a `continue` targeting a higher level control structure is
 actually intended.

 To target the higher level control structure, a numeric argument has to be
 passed to `continue`.

 Refs:
 * http://php.net/manual/en/control-structures.continue.php
 * https://github.com/php/php-src/pull/3364
 * https://wiki.php.net/rfc/continue_on_switch_deprecation

 This change has been recently committed to PHP itself and will break the
 build against `nightly` for the current `master` already.
 See: https://travis-ci.org/WordPress/wordpress-
 develop/jobs/401538006#L828-L831.

 The attached patch fixes the two instances of this in WordPress.

 Notes:
 * Both these switches are nested in other control structures, but end the
 switch at the scope closer of the outer control structure, so using
 `break` in these cases is equivalent to using `continue 2`.


 ----

 FYI: The [https://github.com/wimg/PHPCompatibility PHPCompatibility]
 standard will include a sniff to detect this in the near future. This
 ticket is the result of some tests I've been running on the WIP
 PHPCompatibility sniff :wink:

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


More information about the wp-trac mailing list