Recent Topics

Warning: "continue" targeting switch is equivalent to "break"

Started by on Jun 17, 2019 – Contents updated: Aug 30, 2019

Jun 17, 2019 16:05    

The full warning is

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/calstock/public_html/inc/items/items.ctrl.php on line 338.

Warning: "continue" targeting switch is equivalent to "break"

This happened once when I tried to edit a comment see https://forums.b2evolution.net/comments-do-not-show

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;
				}

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;

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

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

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

Aug 24, 2019 02:22

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

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

This post has 1 feedback awaiting moderation...


Form is loading...

Responsive CMS – This forum is powered by b2evolution CMS, a complete engine for your website.