WordPress.org

Make WordPress Core

Opened 15 months ago

Closed 11 months ago

Last modified 10 months ago

#44543 closed defect (bug) (fixed)

PHP 7.3 compatibility: using `continue` in `switch` statements

Reported by: jrf Owned by: jrf
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch commit fixed-major php73
Focuses: Cc:

Description

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:

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 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:

Attachments (1)

patch-44543.patch (1.4 KB) - added by jrf 15 months ago.

Download all attachments as: .zip

Change History (14)

@jrf
15 months ago

#1 @SergeyBiryukov
15 months ago

  • Milestone changed from Awaiting Review to 5.0

#2 @pento
15 months ago

  • Keywords commit added; 2nd-opinion removed
  • Owner set to jrf
  • Status changed from new to assigned

Patch looks good to me.

#3 @kraftbj
13 months ago

  • Milestone changed from 5.0 to 4.9.9

Bumping it to a minor release to ensure consideration for the next round. PHP 7.3 GA is scheduled for December 13th.

+1 on patch looking good.

#4 @jorbin
12 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 43653:

General: PHP7.3 throws an E_WARNING when using continue to target a switch

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. This fixes two cases in WordPress Core where this is currently happening.

See: https://github.com/php/php-src/pull/3364
See: https://wiki.php.net/rfc/continue_on_switch_deprecation

Props jrf.
Fixes #44543.

#5 @jorbin
12 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for consideration for 4.9.9

#6 @jorbin
12 months ago

#44944 was marked as a duplicate.

#7 @SergeyBiryukov
12 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 43656:

General: PHP 7.3 throws an E_WARNING when using continue to target a switch.

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. This fixes two cases in WordPress Core where this is currently happening.

See: https://github.com/php/php-src/pull/3364
See: https://wiki.php.net/rfc/continue_on_switch_deprecation

Props jrf.
Merges [43653] to the 4.9 branch.
Fixes #44543.

#8 @jrf
12 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopened as this needs to be ported to the 5.0 branch as well.

This ticket was mentioned in Slack in #core-committers by jrf. View the logs.


12 months ago

#10 @pento
12 months ago

  • Milestone changed from 4.9.9 to 5.0

#11 @desrosj
11 months ago

  • Keywords php73 added

#12 @SergeyBiryukov
11 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 43746:

General: PHP 7.3 throws an E_WARNING when using continue to target a switch.

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. This fixes two cases in WordPress Core where this is currently happening.

See: https://github.com/php/php-src/pull/3364
See: https://wiki.php.net/rfc/continue_on_switch_deprecation

Props jrf.
Merges [43653] to the 5.0 branch.
Fixes #44543.

#13 @johnbillion
10 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.