Search code examples
phpstringbuilder

StringBuilder for PHP


Has someone made a StringBuilder implementation in PHP?


Solution

  • 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.