115

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"?

Makoto
  • 104,088
  • 27
  • 192
  • 230
tenderfoot
  • 1,167
  • 2
  • 6
  • 4
  • 3
    Please include your code in the question. (And to the editor, please don't add things to the question that OP hasn't actually said, as helpful as it may seem. It puts words in their mouth and becomes confusing.) – Tyler Roper Jan 14 '19 at 17:45
  • Try "composer update". May or may not help. The warning is a result of a recent php "fix" and requires a slight update to fix. You might also run into the count() null warning. @trincot - And yes the warning is clear. The problem is that it is being generated by a third party library. In a very confusing block of code. – Cerad Jan 14 '19 at 20:54
  • Have you verified whether your server complies with minimum requirements? Current Symfony version is 4.2.3 so it's very unlikely that 2.8 supports PHP/7.3, which was released less than 2 moths ago. – Álvaro González Jan 15 '19 at 08:08
  • I've just checked that, according to [Packagist](https://packagist.org/packages/symfony/symfony#v2.8.49), Symfony/2.8.49 was released the same day than PHP/7.3. So perhaps that version is meant to address compatibility issues (I don't really know). – Álvaro González Jan 15 '19 at 08:10

20 Answers20

149

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.

Miftah Mizwar
  • 3,722
  • 2
  • 13
  • 20
  • If this fails (like for me) next is try the answer from Avnish alok to this question. The composer version installed by apt is to old. – Trevor Sep 01 '19 at 04:02
  • This is the correct answer, though it could use the background information of stating that "Your composer version is too old, update it." This would help people like Trevor above realize that they are on the right path, even is self-update fails. – Matt Rabe Oct 09 '19 at 18:17
  • For me the right solution was just to run `composer update` while on install the error occured, though its totally better to keep composer up to date itself, just saying for those who have to think about what implications might bring this to other projects on the same server ;) – john Smith Aug 13 '20 at 12:06
54

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');"
Avnish Tiwary
  • 2,188
  • 22
  • 27
45

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.

Jon
  • 569
  • 4
  • 7
26

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;

   }

d212digital
  • 385
  • 3
  • 8
23

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!

Arun Panneerselvam
  • 2,263
  • 1
  • 17
  • 24
16

composer self-update composer install

Now, it should works

enter image description here

code-8
  • 54,650
  • 106
  • 352
  • 604
8

In my case php was upgraded from php7.2.22 to php7.3.9.

so had to downgrade cli php as composer is run on terminal

//checked php version
php -v //was 7.3.9

//changed cli version back to 7.2
sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2

//checked php version 
php -v //was 7.2.22

additional info if you are using apache remember to keep both cli and apache in same version. in my case i had to downgrade

//changed web version back to 7.2
sudo a2dismod php7.3
sudo a2enmod php7.2
sudo service apache2 restart

This will work with other versions. so feel free to switch between versions. just replace the version numbers appropriately

aimme
  • 6,385
  • 7
  • 48
  • 65
7

Windows 10 Professional

PHP 7.3.1

I ran these commands to fix the problem on my desktop

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
John Hanley
  • 74,467
  • 6
  • 95
  • 159
6

that seems to be an issue with php7.3, I guess.

If you have different version installed on your system then you could use this:

php7.1 /usr/bin/composer update // or wherever your composer is

it worked for me

Sumit Wadhwa
  • 2,825
  • 1
  • 20
  • 34
4

Or download composer.phar from site: "https://getcomposer.org/download/" (manual download), and use command:

php composer.phar require your/package
Vitalicus
  • 1,188
  • 13
  • 15
4

I think it's a version problem, you just have to uninstall the old version of composer, then do a new installation of its new version.

 apt remove composer

and follow the steps:

  1. download the composer from its official release site by making use of the following command.
 wget https://getcomposer.org/download/1.6.3/composer.phar
  1. Before you proceed with the installation, you should rename before you install and make it an executable file.
  mv composer.phar composer
  chmod +x composer
  1. Now install the package by making use the following command.
 ./composer
  1. The composer has been successfully installed now, make it access globally using the following command. for Ubuntu 16
 mv composer /usr/bin/

for Ubuntu 18

 mv composer /usr/local/bin/
Seck Kader
  • 41
  • 2
4

I've got the same problem when I run composer install
I solve it by doing in composer directory php composer.phar self-update and then in my project directory composer update

Nel
  • 454
  • 5
  • 14
3

after upgrading my xampp from 7.2.0 to 7.3.0 i face this issue but after unistall composer.exe and install latest composer.exe from composer.org than issue resolved

Vijay Kanaujia
  • 439
  • 4
  • 9
3

I had to upgrade doctrine/orm:

composer update doctrine/orm

Updating doctrine/orm (v2.5.13 => v2.6.6)
ivoba
  • 5,780
  • 5
  • 48
  • 55
2

On debian 9 php7.3 the answer above pasted below worked perfectly.


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

I had the same issue. but fixed it by downloading composer & installing it from scratch.

Ahmed Badawy
  • 379
  • 1
  • 6
  • 15
1

If your code cannot be updated on some reason, just change your switch ... continue to switch ... break, as in previous versions of PHP it was meant to work this way.

Mike
  • 378
  • 1
  • 8
1

@aimme's answer should be accepted!

I would extend his answer with @david-baucum's comment because his explanation is clear!

I would also extend his answer that you can run multiple PHP versions at the same time using ppa:ondrej/php.

Then you don't need to change the PHP version simple call the composer like this: /usr/bin/php7.2 /usr/local/bin/composer install

Zoltán Süle
  • 1,482
  • 19
  • 26
1

Sorry for the "diggy up", but i just encoured this issue with an symfony3.8 project deploiement on shared hosting (php 7.3.18)...

I solved this issue by set the php memory limit in the command line options, a stuff like this:

php -dmemory_limit=-1 /path/to/the/executable

J1v3
  • 84
  • 1
  • 9
-7

In order to eliminate this error, you have to fo to the wp-config file and add these lines of code

define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
billdoor
  • 1,999
  • 4
  • 28
  • 54