Javascript required
Skip to content Skip to sidebar Skip to footer

Warning Continue Targeting Switch is Equivalent to Break

1 Jun 17, 2019 16:05

2 Jun 17, 2019 16:19

3 Jun 17, 2019 22:06

I have commented out line 338 in /inc/items/items.ctrl.php and all seems fine. I'm not sure why 'continue' is used as there is no code to continue to before the closing bracket. Lools like an imported code that was used for posts and left from the ancient days??

continue resumes execution just before the closing curly bracket ( } ), and break resumes execution just after the closing curly bracket.
https://www.php.net/manual/en/control-structures.continue.php

                                      if( $new_Chapter->dbinsert() !== false ) 						{ // Category is created successfully 							$Messages->add_to_group( sprintf( T_('New category %s created.'), '<b>'.$new_categories[ $fileNum ].'</b>' ), 'success', T_('Creating posts:') ); 							$ChapterCache->clear(); 						} 						else 						{ // Error on creating new category 							$Messages->add( sprintf( T_('New category %s creation failed.'), '<b>'.$new_categories[ $fileNum ].'</b>' ), 'error' ); 							//continue; // Skip this post 						} 						$cat_Array[ $fileNum ] = $new_Chapter->ID; 						break; 				}                                  

4 Jun 21, 2019 09:41

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/collections/_search.funcs.php on line 1731

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/collections/_search.funcs.php on line 1738

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/collections/_search.funcs.php on line 1744

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/collections/_search.funcs.php on line 1750

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/collections/_search.funcs.php on line 1756

UPDATE: To remove the above errors
I have commented out the lines above that are solely code with continue; to //continue;

UPDATE 2:
Replaced earlier edit with break;

5 Jun 23, 2019 10:59

So to summarise.

In PHP, if continue is applied to a switch statement, it behaves the same as break. In other languages, it would continue the surrounding loop instead. To avoid confusion, this RFC proposes to deprecate and remove continues acting on switch.
https://wiki.php.net/rfc/continue_on_switch_deprecation

As since PHP 7.3.* there is a warning for each instance I'm replacing all instances of continue; with break;

And for those interested I will update the list of files here but not the version or line numbers.

So the list so far is


    • /inc/items/items.ctrl.php
    • /inc/collections/_search.funcs.php
    • /plugins/_bbcode.plugin.php
    Searched a dozen or so files using the [switch] statement but all use break;

6 Jun 23, 2019 11:04

Further Notes

Backward Incompatible Changes
PHP 7.3 throws additional deprecation warnings, PHP 8 generates a compile error. Fixing it is always trivial by replacing continue with break.

Unaffected PHP Functionality
Continue can still be used inside switch statements, as long as it does not target the switch. The meaning of continue and break inside switch never changes, some cases are just forbidden.

To further clarify which uses of continue are affected, please consider the following example:

                    while ($foo) {     switch ($bar) {         case "baz":             while ($xyz) {                 continue;   // Targeting the inner while loop: Allowed                 continue 2; // Targeting the switch: Deprecated                 continue 3; // Targeting the outer while loop: Allowed             }     } }                  

https://wiki.php.net/rfc/continue_on_switch_deprecation

7 Jun 24, 2019 14:02

we'll fix all that.

8 Jun 24, 2019 17:29

9 Jun 24, 2019 19:01

@yurabakhtin Thanks for this and all the others and not just today :)

10 Aug 24, 2019 00:42

I am just getting all of these types of errors today. None of these errors were there earlier this morning. I'm running 6.10.1-stable and can't log in to my dashboard when I could earlier today.

Will doing an update fix this?

-Brae

11 Aug 24, 2019 00:50

I checked with my host, and they wrote, "The PHP version was upgraded to 7.3 automatically which was not compatible with your website . So I changed the PHP version to 5.6 to make it work. "

-Brae

12 Aug 24, 2019 02:22

Yes you should upgrade. b2evo 6.11.3 is compatible with PHP 7.3.

13 Aug 24, 2019 02:25

14 Aug 30, 2019 18:19

@amoun
Once again I find your solutions to be most helpful. You are a terrific asset to the b2evo community. Thanks!
wrc

burnageepaid1957.blogspot.com

Source: https://forums.b2evolution.net/warning-continue-targeting-switch-is-equivalent-to-break