On PHP 7.3, I'm occasionally seeing the following error:

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /sites/all/modules/service_links/plugins/service_links_sprites.module on line 85

Simple fix, attached in the next comment.

CommentFileSizeAuthor
#2 service_links--3084372-2.patch561 byteshargobind

Comments

hargobind created an issue. See original summary.

hargobind’s picture

Status: Active » Needs review
StatusFileSize
new561 bytes

Single line fix.

wylbur’s picture

Issue tags: +PHP 7.3

Adding the PHP 7.3 tag to track this issue. Will test the patch - tomorrow!

wylbur’s picture

We experienced this error when we started testing a Drupal 7 site using PHP 7.3.

"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? service_links_sprites.module:85

Applying the patch in comment #2 resolved the issue.

Marking this as RTBC, but I encourage others that find this issue to also test.

Specifics:
Drupal 7.69
PHP 7.3
Service Links 7.x-2.4

wylbur’s picture

Status: Needs review » Reviewed & tested by the community
wylbur’s picture

mforbes’s picture

I haven't tested the patch yet so I don't mean to say it's wrong, but I just have a question:

Isn't the message basically saying "you're using x which results in execution like y; did you instead mean z"? Therefore if we want a patch to result in no change of execution behavior -- and I assume we want no change in behavior since nothing in this issue mentions buggy logic -- then the patch should replace x with y. The current patch (#2) is replacing x with z instead.

hargobind’s picture

@mforbes:

Looking at this specific code, the switch {} is contained in a for {} loop, and there is additional code after the switch {} statement. That remaining code relies on a variable that is only set in the switch {}.

It appears that the continue was meant to skip the code after the switch {} and move on to the next iteration of the for {} loop. Instead, the continue (without "2") acts like a break statement which only halts the switch {} execution but continues to execute the rest of the code in the for {} loop.

If we let execution continue to run on the remaining code in the for {}, it will cause an error. So this patch actually keeps the original intended logic.

paulrooney’s picture

I confirm that the patch in comment #2 resolves the issue.

Drupal 7.72
PHP 7.3
Service Links 7.x-2.4

hargobind’s picture

Issue tags: +PHP 7.4

Thanks @paulrooney.

Adding PHP 7.4 issue tag for better visibility.

chike’s picture

Using PHP 7.4, patch #2 solved the issue.