References used in foreach loops should be unset

Created on 15 June 2023, over 1 year ago

Problem/Motivation

Running sonarqube we found this issue on ln 1454 of WebformElementBase.php, & ln 39 of WebformTranslationLingotekManager.php: Make sure that the referenced value variable is unset after the loop.
Why is this a problem?
When a reference is used in a foreach loop instead of using a simple variable, the reference remains assigned and keeps its "value" which is a reference, even after the foreach execution. Most of the time, this is not what the developer is expecting and the reference may be used wrongly in the rest of the code. For this reason, it is recommended to always unset a reference that is used in a foreach to avoid any unexpected side effects.

Steps to reproduce

The proposed solution is unset the referenced variable after the loop

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

6.1

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain paucala

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024