.. _structures-staticloop: .. _static-loop: Static Loop +++++++++++ `Static `_ loop may be preprocessed. It looks like the following loops are `static `_ : the same code is executed each time, without taking into account loop variables. It is possible to create loops that don't use any blind variables, though this is fairly rare. In particular, calling a method may update an internal pointer, like `next() `_ or ``SimpleXMLIterator\:\:`next() `_``. It is recommended to turn a `static `_ loop into an expression that avoid the loop. For example, replacing the sum of all integers by the ``function $n * ($n + 1) / 2``, or using `array_sum() `_. This analysis doesn't detect usage of variables with ``compact``. .. code-block:: php Connex PHP features ------------------- + `loop `_ Suggestions ___________ * Precalculate the result of that loop and removes it altogether * Check that the loop is not missing a blind variable usage * Replace the usage of a loop with a native PHP call : for example, with str_repeat(). Although the loop is still here, it usually reflects better the intend. Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Structures/StaticLoop | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze `, :ref:`Changed Behavior ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.8.4 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Slow (1 hour) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | High | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+