String builder optimization (ARCH7071)
Key php.performance.string-builder-optimization · Severity info · Category performance
Chaining many parts with . in a single expression is hard to read and inefficient. Use a format string or implode() instead.
Incorrect
Section titled “Incorrect”<?php$line = $id . ' - ' . $name . ' (' . $age . ') ' . $city . ', ' . $country;echo $line;Correct
Section titled “Correct”<?php$line = sprintf('%d - %s (%d) %s, %s', $id, $name, $age, $city, $country);echo $line;Build multi-part strings with sprintf() or implode() in a single expression.