2 ms·
Deprecated variables in strings? Or just when using the curly braces syntax for some reason? Unlike with every other entry there's no link but this sounds like
by Aachen 4y ago
Deprecated variables in strings? Or just when using the curly braces syntax for some reason? Unlike with every other entry there's no link but this sounds like the biggest change since PHP 4. Anyone know where to find more info?
- TimWolla 4y agoOnly this specific curly braces syntax, which is less powerful than the still-supported '{$foo}' variant: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation https://wiki.php.net/rfc/deprecate_dollar_brace_string_inter...
- Aachen 4y agoAh, okay that's a much smaller change then. Thanks for the info and link! Kinda odd that Bash has had this syntax since forever, Perl as well, JavaScript went out of its way to add it as well, and now php is like: let's remove this syntax specifically but allow typo variants of it! Oh well. Not like I was using it, that is, I use the bare "$foo" syntax and try not to make string interpolation too complicated with inline expressions or some such. Just, I could have seen the logic behind switching to the more universally supported syntax and deprecating something else rather than doing their one-off thing.
- colonwqbang 4y agoIn bash/shell the expression $a is "just" a shorthand for ${a}, which is the more general syntax. Shell does not really make a distinction between string interpolation and ... well, everything else. It's a bit like how we don't always have to write out the curly braces of an if statement in C. I'll also point out that in shell assignment looks like a="foo" not $a="foo" The dollar sign of shell feels to me more like an operator you use when you want to access the value of a variable. Not a part of the name of the variable as in PHP.
- jorams 4y agoPHP string interpolation has 3 possible syntaxes: $var, {$var} and ${var}. The last one is now deprecated. I've never seen it used in the wild, and it has some odd limitations. It's discussed in the RFC[1]. [1]: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation https://wiki.php.net/rfc/deprecate_dollar_brace_string_inter...
- capableweb 4y agoInteresting that one developer voted no (out of 32 developers in total). Wonder what the reasoning was? Seems like a change with small impact and reduced amount of code to maintain, so not lots of drawbacks.
- tyingq 4y ago>I've never seen it used in the wild I imagine it might crop up for people that also use Perl, since that would be more common there, like: $foo="abc${var}def";
- trey-jones 4y agobash also uses the same syntax, and I've probably used it before for that reason.
- alt227 4y agoSeems strange to remove it when Javascript has introduced it with backtick strings like: `words ${var} more words` I thought we would start seeing more usage of this in PHP to make things more consistent.
- graypegg 4y agoThe ${var} syntax is inconsistent with PHP’s own syntax though. Variables are normally referenced with a leading dollar sign, like $var, so if you wanted to make it look like template strings in JS it’d be ${$var} which is over complicated.