28.14. Avoid Concatenation of Large Strings

A very common practice in PHP is to needlessly concatenate large chunks of data before printing them. Compare Listing 28.9 to Listing 28.10. The concatenation of subject and contents has to happen before the script calls print, and if the size of contents is very big, it can consume a lot of time. Listing 28.10 calls print multiple times; PHP never needs to concatenate subject and contents in memory, which saves valuable time. Note that since calling print itself has some overhead, it may not always be advisable to separate concatenations into multiple print statements. In certain cases it may also make the code less readable. For that reason, it's best if you follow this practice only when displaying ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.