3 ms·
Don't panic: this deprecates `${var}`, which is a less-common syntax for interpolation, but leaves the most common ones, `$var` and `{$var}`, in place. It redu
by dreadnaut 4y ago
Don't panic: this deprecates `${var}`, which is a less-common syntax for interpolation, but leaves the most common ones, `$var` and `{$var}`, in place.
It reduces the number of slightly different ways to do one thing, and clears the ground for adding any-expression interpolation, which PHP is currently missing.
- dgb23 4y agoI'm not worried about the deprecation itself. I'm worried about the second argument you're making. This RFC trades stability for nicer syntax that isn't really needed. PHP is already great with strings. If the deprecation was indefinite and there wasn't a language feature waiting that relies on removing this, then I would not be worried at all. Will the implications be bad in this case? Probably not? It's the mentality behind that makes me uneasy.
- dhzhzjsbevs 4y agoPHP has been modernising for years. This particular change feels like a bad move to me (pointless) but it's part in parcel with them modernising overall and I don't want to discourage that as most of the improvements have been extremely beneficial. Speed upgrade from 5 to 7 was insane.
- teruakohatu 4y agoBut why remove it in the first place. Is it such a burden on the parser or mental overhead for developers?
- the_mitsuhiko 4y ago> clears the ground for adding any-expression interpolation, which PHP is currently missing
- sam_goody 4y agoBecause this syntax is used for variable variables as well as interpolation. By removing the interpolation, it makes the remaining code more predictable and less likely to have a footgun.
- jeroenhd 4y agoI've never known that "{$var}" was even allowed. All other languages using $ for string interpolation use the "${var}" pattern, often also allowing any expression ("${var / 10 + 2}") within the brackets. Keeping "{$var}" seems like a strange decision to me. I assume the people who made the decision analysed open source projects and evaluated which option gets used most, but it doesn't feel like the most obvious decision to me.
- mike_d 4y agoYou'd have to rewrite a good portion of all existing PHP code to eliminate the "{$var}" syntax. It is the "right" way to include variables in a string.
- BrianHenryIE 4y agoPHPStorm/PHPStan (I'm not certain which) will tell me `"My {$var} string"` doesn't need the `{}`, but won't give me the same notice when using `"My {$obj->getVar()} string"`. Personally, I prefer keeping the `{}`.
- innocenat 4y ago"{$arr[2]}" for array and object, {} is required.