Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? [closed]

Tags:

php

symfony

I have php7.3 and symfony2.8 When I try to create the classes with the console I get this error:

[Symfony\Component\Debug\Exception\ContextErrorException]Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

like image 664
tenderfoot Avatar asked Jan 14 '19 15:01

tenderfoot


People also ask

What does “continue” targeting switch is equivalent to?

Warning: “continue” targeting switch is equivalent to “break”. did you mean to use “continue 2” – What’s going on? When you are using PHP 7.3, you may get a Warning: “continue” targeting switch is equivalent to “break”.

Why do I get a “continue” warning when targeting switch?

When you are using PHP 7.3, you may get a Warning: “continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”. This issue appears because of a backward incompatibility with PHP 7.3 for the continue keyword in Switch statements.

What is the difference between break and continue in PHP?

Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed) but will raise a warning as this is likely to be a mistake. If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

What is the difference between break and continuemeans in C?

In most sanelanguages, in particular those that derive from C, the two keywords do not have the same meaning: breakmeans “exit from the current loop immediatly”; continuemeans “stop the current iteration and restart the loop from the very next one”.


5 Answers

I've got same problem and got this error too, but in my case this error shows when i'm trying to run composer install or composer update.

and i solve this issue by running composer self-update. it works on my project.

like image 84
Miftah Mizwar Avatar answered Oct 28 '22 21:10

Miftah Mizwar


Maybe your composer is outdated. Below are the steps to get rid of the error.

Note: For Windows professionals, Only Step2 and Step3 is needed and done.


Step1

Remove the composer:

sudo apt-get remove composer

Step2

Download the composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Step3

Run composer-setup.php file

php composer-setup.php

Step4

Finally move the composer:

sudo mv composer.phar /usr/local/bin/composer  


Your composer should be updated now. To check it run command:

composer

You can remove the downloaded composer by php command

php -r "unlink('composer-setup.php');"
like image 43
Avnish alok Avatar answered Oct 28 '22 20:10

Avnish alok


The issue looks to me to be a backward incompatibility with PHP 7.3 for the continue keyword in Switch statements. Take a look at the "Continue Targeting Switch issues Warning" section in Backward Incompatible Changes.

I ran into the same issue with Symfony 3.3 using PHP 7.3 and downgrading to PHP 7.2 resolved the warning.

like image 44
Jon Avatar answered Oct 28 '22 20:10

Jon


I upgraded to PHP 7.3, and None of these worked for me before I used,

sudo wget https://getcomposer.org/download/1.8.0/composer.phar -O /usr/local/bin/composer && sudo chmod 755 /usr/local/bin/composer

It's just the version dependency. PHP 7.3

and composer update worked like a charm!

like image 23
Arun Panneerselvam Avatar answered Oct 28 '22 20:10

Arun Panneerselvam


I changed continue to continue 2 on line 1579 in shortcodeComon.php and it fixed my problem

   if(trim($custom_link[$i]) == ""){

           continue;

    }

Change to:

  if(trim($custom_link[$i]) == ""){

             continue 2;

   }

like image 22
d212digital Avatar answered Oct 28 '22 19:10

d212digital