Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2.8 and PHP 7.4: Warning: "continue" targeting switch is equivalent to "break". Composer is at latest version

I am trying to update a symfony 2.8 application to use PHP 7.4, but when I try to clear the cache php app/console cache:clear I get the following warning:

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

which results in "script exited with non-zero code". That messes up the whole automation process of Jenkins. The solutions I ran at were generally a simple composer update, but after I did this and updated composer to the latest version (currently 2.0.7), the error still persists, and I'm sure it's not a composer issue, as this warning crashes even the symfony-only cache:clear command. I was thinking about creating my own fork of symfony from this particular version branch and fixing the errors myself, but I cannot find the exact spot this continue occurs.

How to eliminate this error, or at least how to debug the whole process, so I can fix the error myself?

Any help is appreciated. Thanks in advance!

Edit:

This is the message that is returned after running php app/console cache:clear --verbose. I don't see any sign of potential continue bug. Does any of you see something like this?

Exception trace:
() at 
/var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:2636
Symfony\Component\Debug\ErrorHandler->handleError() at
/var/www/html/vendor/symfony/symfony/src/Symfony/Component/Debug/DebugClassLoader.php:169

 require() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Debug/DebugClassLoader.php:169
 Symfony\Component\Debug\DebugClassLoader->loadClass() at n/a:n/a
 spl_autoload_call() at /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:160
 Doctrine\ORM\EntityManager->__construct() at /var/www/html/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:850
 Doctrine\ORM\EntityManager::create() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:1711
 appDevDebugProjectContainer->getDoctrine_Orm_DefaultEntityManagerService() at /var/www/html/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /var/www/html/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:183
 Doctrine\Common\Persistence\AbstractManagerRegistry->getManager() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:9401
 appDevDebugProjectContainer->getFosUser_EntityManagerService() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:2945
 appDevDebugProjectContainer->getFosUser_UserManagerService() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:9219
 appDevDebugProjectContainer->getValidator_BuilderService() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:9201
 appDevDebugProjectContainer->getValidatorService() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/app/cache/dev/appDevDebugProjectContainer.php:8349
 appDevDebugProjectContainer->getSonata_Adminbundle_Command_ExplainadmincommandService() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:295
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:147
 Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:112
 Symfony\Bundle\FrameworkBundle\Console\Application->all() at /var/www/html/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:66
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /var/www/html/app/console:28
like image 371
Emil Avramov Avatar asked Oct 25 '25 14:10

Emil Avramov


1 Answers

Symfony 2.8 is no longer supported, and it hasn't been made compatible with PHP 7.4 (as this was release after the last fixes for Symfony 2.8). You could check where exactly that error occurs and try to fix it (usually the full error message should contain such information), or you have to update Symfony 2.8 as well to a supported version.

Edit: after you've presented more details, I assume that you are using doctrine/orm in v2.5.14. This has been released in Dec 2017, and this was the latest version to be compatible with Symfony 2.8. As PHP 7.3 (in which the deprecation of continue with switch was introduced) was released in Dec 2018, it's not a surprise that such a problem has not been fixed in the ORM package.

You should either stick to PHP 7.2, or update Symfony, Doctrine, and whatever bundles you are using to more recent ones.

like image 88
Nico Haase Avatar answered Oct 27 '25 05:10

Nico Haase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!