StringBuilder for PHP

Mark picture Mark · Nov 18, 2010 · Viewed 44.5k times · Source

Has someone made a StringBuilder implementation in PHP?

Answer

Mark Baijens picture Mark Baijens · Nov 18, 2010

Note:

This answer is from 2010, there might be stringbuilders that can improve the performance by now (judging from the comments below). I have not worked with php for a long time so my knowledge is not up to date. This answer might be out dated.

The following question might provide interesting information as well, all tough their conclusion seem to be the same.

php String Concatenation, Performance


Why do you want to use a StringBuilder? Strings in php are mutable. Therefore performance is not an issue.

Just build string like this

$string = "start";
$string .= "appended string";
$string .= "appended string";
etc.