zlacker

[parent] [thread] 9 comments
1. Aachen+(OP)[view] [source] 2022-12-08 12:53:44
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?
replies(2): >>TimWol+i >>jorams+q
2. TimWol+i[view] [source] 2022-12-08 12:55:48
>>Aachen+(OP)
Only this specific curly braces syntax, which is less powerful than the still-supported '{$foo}' variant: https://wiki.php.net/rfc/deprecate_dollar_brace_string_inter...
replies(1): >>Aachen+C1
3. jorams+q[view] [source] 2022-12-08 12:57:16
>>Aachen+(OP)
PHP 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_inter...

replies(3): >>capabl+Y >>tyingq+t1 >>alt227+43
◧◩
4. capabl+Y[view] [source] [discussion] 2022-12-08 13:00:47
>>jorams+q
Interesting 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.
◧◩
5. tyingq+t1[view] [source] [discussion] 2022-12-08 13:04:41
>>jorams+q
>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";

replies(1): >>trey-j+R2
◧◩
6. Aachen+C1[view] [source] [discussion] 2022-12-08 13:05:35
>>TimWol+i
Ah, 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.

replies(1): >>colonw+M2
◧◩◪
7. colonw+M2[view] [source] [discussion] 2022-12-08 13:13:43
>>Aachen+C1
In 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.
◧◩◪
8. trey-j+R2[view] [source] [discussion] 2022-12-08 13:13:59
>>tyingq+t1
bash also uses the same syntax, and I've probably used it before for that reason.
◧◩
9. alt227+43[view] [source] [discussion] 2022-12-08 13:14:57
>>jorams+q
Seems 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.

replies(1): >>graype+P9
◧◩◪
10. graype+P9[view] [source] [discussion] 2022-12-08 14:04:04
>>alt227+43
The ${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.
[go to top]