.. _structures-overwrittenforeachvar: .. _overwritten-foreach-var: Overwritten Foreach Var +++++++++++++++++++++++ When using standard blind variable names, nested foreach may lead to overwriting the variables. Careful coding may take advantage of that feature. Though, it tends to be `error `_ prone, and will generate bugs if the code is refactored. .. code-block:: php $value) { foreach($array as $key2 => $value) { // $value is now the one of the 2nd foreach, not the first. } } ?> Connex PHP features ------------------- + `foreach `_ Suggestions ___________ * Change the name of one of the blind variable to use a distinct name * Remove usage of one of the double variable * Remove the nested foreach() * Move the nested foreach() to a method Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Structures/OverwrittenForeachVar | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 2.3.2 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Major | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Quick (30 mins) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+