.. _structures-noappendonsource:
.. _no-append-on-source:
No Append On Source
+++++++++++++++++++
Do not append new elements to an array in a foreach loop. Since PHP 7.0, the array is still used as a source, and will be augmented, and used again.
Thanks to `Frederic Bouchery `_ for the reminder.
.. code-block:: php
See also `foreach `_ and `What will this code return? #PHP `_.
Connex PHP features
-------------------
+ `class `_
Suggestions
___________
* Use a copy of the source, to avoid modifying it during the loop
* Store the new values in a separate storage
Specs
_____
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Short name | Structures/NoAppendOnSource |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior ` |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 1.8.2 |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| PHP Version | All |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Precision | Very high |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition `_, `Exakat Cloud `_ |
+--------------+-------------------------------------------------------------------------------------------------------------------------+