While running PHP compatibility sniffs on feeds I encountered:

FILE: /sites/all/modules/feeds/mappers/file.inc
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------
 193 | WARNING | Targeting a 'switch' control structure with a 'continue' statement is strongly discouraged and will throw a warning
     |         | as of PHP 7.3.
---------------------------------------------------------------------------------------------------------------------------------------

After reading https://wiki.php.net/rfc/continue_on_switch_deprecation I realized that this might point to a subtle bug if the author was attempting to achieve the behavior of continue 2.

Thought I'd raise this here for consideration by someone more familiar with this code.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bwood created an issue. See original summary.

bwood’s picture

Issue summary: View changes
ansergeyg’s picture

As far as I understood from the example here:

https://wiki.php.net/rfc/continue_on_switch_deprecation

continue 2 is targeting not the closest looping structure but the second closest.

in our case we have this structure:

foreach() //first looping structure
{
	some code here:
	switch() //second looping structure - the closest one
	{
		case:
			continue; 
		break;
	}
	
	some code here;
}

By default the documentation says:

https://www.php.net/manual/en/control-structures.continue.php

Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed). If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

In our case the continue statement has no parameters set. It means it behaves as a break statement.

But it also means we have two break statements in one case block.

So I just removed the continue statement because according to the experiments with try/catch block in the loop provided here:

https://stackoverflow.com/questions/4673483/php-try-catch-block-inside-loop

Catch block suppresses the interruption thrown by an exception and the code
continues to execute and gets to the last break statement.

<?php
foreach ($values as $v) {
	if ($info['cardinality'] == $delta) {
	  break;
	}

	if (!isset($field[$language][$delta])) {
	  $field[$language][$delta] = array();
	}

	switch ($sub_field) {
	  case 'alt':
	  case 'title':
	  case 'description':
		$field[$language][$delta][$sub_field] = $v;
		break;

	  case 'uri':
		$skip = FALSE;
		if ($v) {
		}

		try {
			$v->setAllowedExtensions($instance_info['settings']['file_extensions']);
			$field[$language][$delta] += (array) $v->getFile($destination, $mapping['file_exists']);
			// @todo: Figure out how to properly populate this field.
			$field[$language][$delta]['display'] = 1;
		  }
		  catch (Exception $e) {
			watchdog('feeds', check_plain($e->getMessage()));
		        continue;
	   }
	  break;
	}
	
	$delta++;
}
?>

So there is only

$delta++;

After the switch code. There is a possibility that delta can be counted differently, but I suppose removing the continue will not affect the delta.

mradcliffe’s picture

Version: 7.x-2.0-beta4 » 7.x-2.x-dev
Status: Active » Needs review

I set the issue to Needs review since there is a patch posted for review, and added a test run for 7.x-2.x-dev on PHP 7.2.

I haven't looked at the patch, but will try to test it out manually on a site soon.

blackbull77’s picture

Has there been any news on if the patch is ok to use?

wylbur’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +PHP 7.3

We tested this today on a D7 site with the following config:
drupal 7.69
Feeds 7.x-2.0-beta4
PHP 7.3

When running cron via drush, feeds module is fired, and produced errors in the terminal

"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? file.inc:193

Applying the patch #3 resolved the errors.

Also note that we received no errors in the watchdog logs about this error.

Tagging this issue as PHP 7.3, and set to RBTC, but if others find this issue please test!

mradcliffe’s picture

It looks like the test failures in the patch are the same test failures in HEAD for this module.

MegaChriz’s picture

@mradcliffe
Yes, apparently something changed recently in the Link module that causes tests to fail. I haven't looked into it yet, cause I've other Feeds issues I'd like to finalize first.

wylbur’s picture

MegaChriz’s picture

MegaChriz’s picture

Title: 'continue' used within 'switch' control structure » PHP 7.3: 'continue' used within 'switch' control structure

Closed #3115098: PHP 7.3 related: Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2" as a duplicate. Therefore changing title to make this issue hopefully better findable.

VladimirAus’s picture

VladimirAus’s picture

Status: Needs review » Reviewed & tested by the community

Sorry. Ended up producing the same patch :/

Karishma Rawat’s picture

Assigned: Unassigned » Karishma Rawat
Karishma Rawat’s picture

Patch #3 works for me and resolved my PHP Compatibility warning.Please find the screenshot for the same.

Karishma Rawat’s picture

Assigned: Karishma Rawat » Unassigned
joelpittet’s picture

RTBC++

MegaChriz’s picture

@joelpittet
Yes, I really should try to find time to get the D7 version of Feeds compatible with recent PHP versions.

joelpittet’s picture

@MegaChriz if you're interested I don't mind doing light maintenance on D7 if you'd like to keep your focus on D8? Feel free to add me to the project (let me know if you'd like a formal request in a ticket).

MegaChriz’s picture

@joelpittet
I've given you commit access :). Thanks for your support.

  • joelpittet committed d742a69 on 7.x-2.x authored by ansergeyg
    Issue #3013743 by VladimirAus, ansergeyg, Karishma Rawat, MegaChriz,...
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Great thanks @MegaChriz! I've committed this and credited

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.