Rule Definition
When placed in a loop, string concatenation results in the creation and garbage collection of large numbers of temporary objects. This both consumes memory and can dramatically slow the script execution. It is recommended to avoid string concatenations in loops.
Remediation
Modify the source code to reduce the number of Sections containing string concatenations.
Violation Code Sample
for ($i=0;$i<10;$i++)
{
$str1. $str2;
}
Fixed Code Sample
<?php
$str3 = "this is string 1 this is string 2"; //violation removed
?>
Reference
PHP Code Sniffer: https://pear.php.net/package/PHP_CodeSniffer/docs/2.5.0/PHP_CodeSniffer/Generic_Sniffs_Strings_UnnecessaryStringConcatSniff.html
Related Technologies
Technical Criterion
Efficiency - Expensive Calls in Loops
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.