this is more of a better-practice type of question.
I'd like to know if using brackets in double-quoted strings for variables is good practice.
For example:
<?php
$Variable = 'a variable';
$SingleQuotedString = 'Single quoted string with ' . $Variable;
// Single quoted string with a variable
$DoubleQuotedString = "Double quoted string with $Variable";
// Double quoted string with a variable
$DoubleQuotedStringWithBrackets = "Double quoted string with {$Variable} in brackets.";
// Double quoted string with a variable in brackets.
?>
It doesn't change the output or the code from simple tests, and obviously works. I'm just confused because not many people do this, and I don't see recommendations or people disagreeing with it, and I've been using them just fine.
Thanks for any feedback!
The curly braces are to allow the use of arrays and objects, i.e:
$string = "my array value: {$foo['bar']}";
or
$string = "my object value: {$foo->bar}";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With