Opened 6 weeks ago
Last modified 6 weeks ago
#64472 new defect (bug)
PHP Warning: "continue" targeting switch in wp-admin/includes/upgrade.php line 3073
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 6.9 |
| Component: | Upgrade/Install | Keywords: | close |
| Focuses: | Cc: |
Description
WordPress 6.9 triggers a PHP warning when running on PHP 7.3+ due to incorrect usage of continue statement within a switch block that is nested inside a foreach loop.
## Environment
- WordPress Version: 6.9
- PHP Version: 8.4.7 (also affects PHP 7.3+)
- File:
wp-admin/includes/upgrade.php - Line: 3073
## Error Message
PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /wp-admin/includes/upgrade.php on line 3073
## Stack Trace
PHP Stack trace:
PHP 1. {main}() /wp-admin/tools.php:0
PHP 2. require_once() /wp-admin/tools.php:40
PHP 3. require_once() /wp-admin/admin.php:35
PHP 4. require_once() /wp-load.php:50
PHP 5. require_once() /wp-config.php:107
PHP 6. do_action($hook_name = 'init') /wp-settings.php:742
PHP 7. WP_Hook->do_action($args = [0 => '']) /wp-includes/plugin.php:522
PHP 8. WP_Hook->apply_filters($value = '', $args = [0 => '']) /wp-includes/class-wp-hook.php:365
## Root Cause
In wp-admin/includes/upgrade.php, starting at line 3018, there is a foreach loop that contains a switch statement (line 3028). At line 3073, a continue statement is used within the switch block.
### Current Code Structure (lines 3018-3074):
php
foreach ( $flds as $fld ) {
// ... code ...
switch ( $fieldname_lowercased ) {
case '':
case 'primary':
case 'index':
case 'fulltext':
case 'unique':
case 'key':
case 'spatial':
$validfield = false;
// ... regex matching code ...
// Skip if regex didn't match (malformed KEY definition).
if ( empty( $index_matches['index_type'] ) ) {
continue; // LINE 3073 - PROBLEMATIC
}
// ... more code ...
break; // LINE 3133
}
// ... code ...
}
## Problem Explanation
Since PHP 7.3, using continue inside a switch statement is treated as equivalent to break (it only exits the switch, not the loop). This behavior change was introduced to prevent bugs and improve code clarity.
The intent at line 3073 appears to be to skip to the next iteration of the foreach loop, not just exit the switch statement. Therefore, continue 2 should be used instead.
Hi there, welcome to WordPress Trac! Thanks for the ticket.
Replying to phuochoit:
There is indeed a
foreachloop starting at line 3018, however there is nocontinuestatement at line 3073, or anywhere within thatswitchstatement. It appears that the code on your site may have been edited and includes custom modifications.