WordPress Error - Warning: "continue" targeting switch is equivalent to "break"

PHP warning Continue targeting switch is equivalent to break.

Today I moved a customer's WordPress blog to a subdomain because she wanted to run the site in a kind of internal area. The main domain should be redirected for this.

After I had set up the subdomain in Ionos and loaded all WordPress data into the new directory, I got the following message when I called up the login page:

Warning: "Continue" targeting switch is equivalent to "break".

This PHP error did not appear on the page before, which puzzled me.

This PHP warning came from my customer's website: "Warning: continue targeting switch is equivalent to break." In this case it was due to an outdated plugin, but there were also files in the theme that triggered the error.
This PHP warning came up on my client's website: "Warning: continue targeting switch is equivalent to break." In this case it was due to an outdated plugin, but there were also files in the theme that were triggering the error.

Error message appears from PHP 7.3

My suspicion that the error message had something to do with the PHP version of the hosting did not disappoint. As I saw in the hosting administration, the main domain was running PHP 7.2, while the subdomain was automatically set to PHP 7.4.

I then changed the PHP version of the subdomain to PHP 7.2 and lo and behold: the error had disappeared.

At Ionos you can choose the PHP version for every domain and subdomain.
At Ionos you can choose the PHP version for every domain and subdomain.

The change can be found at Ionos under “Hosting overview” and then in the “PHP” area.

The reason why a change was made in PHP can be found in the PHP Wiki:

In PHP, when continue is applied to a switch statement, it behaves just like break. In other languages, it would continue the surrounding loop instead. To avoid confusion, the RFC suggests that continues that affect switch be discarded and removed.

Adaptation of the code for PHP 7.3, 7.4 and following versions

Now there was a little problem: Ionos has announced that they will end support for PHP 7.2 in December 2020. The consequence would be that the error messages would pop up for my customer from one day to the next - not a good advertisement for her.

For this reason I was looking for a solution to revise your old theme so that it can be used for a few more years.

In order to fix the errors, you can now change a small command that you can find via the error message. One looks for a formulation similar to this:

switch ($ variable) {case "value": continue; }

and swaps the "continue" into a "break":

switch ($ variable {case "value": break;}

In this way you can gradually fix the errors and get your WordPress up and running again.

If you have any problems with your blog, please let me know. I offer a kind of WordPress emergency help with a friend and we help bloggers or companies when it comes to getting the website up and running again.

Did you like the article and did the instructions on the blog help you? Then I would be happy if you the blog via a Steady Membership would support.

2 comments on “WordPress Error – Warning: “continue” targeting switch is equivalent to “break””

  1. Hello, I have this problem too, my pages show: Warning: “continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”? in /WWWROOT/235512/htdocs/wp-content/plugins/slimjetpack/modules/infinite-scroll/infinity.php on line 147
    Will now try to solve this according to your instructions. LG from the beautiful Lower Rhine

Post a comment

Your e-mail address will not be published. Required fields are marked with * marked

In the Sir Apfelot Blog you will find advice, instructions and reviews on Apple products such as the iPhone, iPad, Apple Watch, AirPods, iMac, Mac Pro, Mac Mini and Mac Studio.