Lord Yggdrasill;11013277 wrote:Is it easier to read now? Well for me it is, people are different though so I cant say the same for those who prefer using concatenation all the time. It's a matter of religion after all.
...? this is not directly an issue with concatenation, and curly brackets are not an alternate concatenation operator.
it's certainly not a matter of preference or "religion" - brackets serve a very specific purpose.
<?php
// try this (doesn't work: {}s DON'T concatenate!):
$var1 = 'hello ';
$var2 = 'world';
print {$var1}{$var2};
// now try this (NO concatenation):
print "{$var1}{$var2}";
// and this (concatenation):
print "$var1"."$var2";
// and, to mix things up:
$varArray = array( $var1,$var2 );
print "$varArray[0]$varArray[1]"; // ambiguous
print "{$varArray[0]}{$varArray[1]}"; // not ambiguous
the purpose of the curly brackets is to resolve ambiguity. Take your earlier example:
// (missing sentences)
$sentence1 = "This is sentence one.";
$sentence4 = ". Sentence four includes the missing punctuation from sentence three, for some reason";
// this is not concatenation: it's all *one* string.
"{$sentence1}Sentence 2 is here. Sentence 3 coming along{$sentence4}Now we have sentence 5.";
// without the {brackets}, PHP would look for the variable `$sentence1Sentence`,
// because it doesn't know that `Sentence` is intended to be literal text.
// the {brackets} mark which part is the variable.
// Similarly, in this example, the brackets are *completely unnecessary*:
"{$sentence1} Sentence 2 has leading whitespace. Sentence 3 coming along{$sentence4}-Now we have sentence 5.";
// try it without them
print "$sentence1 Sentence 2 has leading whitespace. Sentence 3 coming along$sentence4-Now we have sentence 5.";