11

When I run ...

composer install

... on a server with PHP and nginx installed.

I get the following exception:

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

How can I fix this?

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
Kumanan
  • 420
  • 1
  • 4
  • 11
  • 1
    probably composer version is old, please try `composer self-update`, or install latest from composer site. – dparoli Aug 12 '19 at 11:16

5 Answers5

5

This is a new warning introduced in PHP 7.3.

It means you are not allowed to have a continue statement inside of a switch, you should use break instead.

To fix this you most likely just have to update composer, this can be done simply by running composer self-update.

You can also just run php without warnings, this can be done by setting the ini config values as a start parameter.

php -d error_reporting=0 composer.phar
Oliver Nybroe
  • 1,828
  • 22
  • 30
2

Check your current PHP version if it's greater than 7.2, then execute follow below simple steps

1. Disable the latest php version

sudo a2dismod php7.3

2. Restart the nginx service

sudo service nginx restart

3. If you are using Apache2 run as below

sudo service apache2 restart

4. Set alternatives

sudo update-alternatives --set php /usr/bin/php7.2

5. Check the PHP version

php -v

6. Now, Install Composer as below

composer install
Kumanan
  • 420
  • 1
  • 4
  • 11
2

Old composer uses continue statement in their code within the switch which is outdated and cannot be used anymore with latest version of php.

you need to update your composer

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

for more details visit composer download

0

It was because of an outdated composer. After searching a lot finally the following works for me:

  1. Uninstall the old composer.
  2. Install a new updated composer.

You can download or install composer from this link: https://getcomposer.org/download/

Siddiqui Noor
  • 5,575
  • 5
  • 25
  • 41
0

For me, just go to this file

sudo nano /usr/share/php/Composer/DependencyResolver/RuleSetGenerator.php

As a quick and dirty alternative, you can fix the error in that file. Just replace "continue" with "break"

albus_severus
  • 3,626
  • 1
  • 13
  • 25