Q:

PHP performance: appending vs prepending strings

Which is more performant: ($longstring . $longstring) . $longstring, or $longstring . ($longstring . $longstring)? Is PHP's concatenation operator left- or right-associative? Is its associativity optimal, or should I override its associativity with parentheses?

A:

$x . $y . $z is the same as ($x . $y) . $z
However, there is no performance to be gained via either approach. It's like:
// ($x . $y) . $ z
$tmp = $x . $y;
return $tmp . $z;

vs
// $x . ($y . $ z)
$tmp = $y . $z;
return $x . $tmp;

In both cases, the same amount of concatenations are occurring. If one method were faster (but neither are), then it would be dependent on the lengths of $x, $y, and $z. (i.e., Is it faster to append a short string to a long string, or to append a long string to a short string is really the question you are asking. Without testing, I'd say the difference is insignificant.)
Now, these are different: $x .= $y and $x = $y . $x. The first is the single ASSIGN_CONCAT append operation, which might be measurably faster than prepending (CONCAT, ASSIGN). Note that $x = $x . $y, while functionally equivalent to $x .= $y, is also two operations. So that style of appending would have the same performance difference (if any) as prepending.

