Removal of ${} string interpolation in PHP 9

php.internals

Ilija Tovilo

4 years ago
Hi everyone It was pointed out to me that unfortunately the "Deprecate ${} string interpolation" RFC didn't specify *how* the feature would be removed in PHP 9. https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation https://github.com/php/php-src/issues/8501 There are two approaches: * Completely remove the syntax and make "${}" result in the literal string "${}" * Keep the syntax in the parser but throw an error It's pretty clear to me that the latter is preferable for two reasons: 1. People upgrading directly from <=PHP 8.1 to PHP 9.0 or people who have not addressed the deprecations will still get an appropriate compile-time error message instead of their code suddenly behaving differently. 2. We can reuse the syntax at some point without causing another BC break. The only advantage of the former approach I can think of is easier (or rather no) escaping of ${} in strings but this could also be a drawback considering that it would become unclear what the original intent of the code was (literal output or string interpolation). So unless there are concerns I will amend that in the RFC. Regards, Ilija

Ben Ramsey

4 years ago
On 5/20/22 04:05, Ilija Tovilo wrote:
> Hi everyone > > It was pointed out to me that unfortunately the "Deprecate ${} string > interpolation" RFC didn't specify *how* the feature would be removed > in PHP 9. > > https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation > https://github.com/php/php-src/issues/8501 > > There are two approaches: > > * Completely remove the syntax and make "${}" result in the literal string "${}" > * Keep the syntax in the parser but throw an error > > It's pretty clear to me that the latter is preferable for two reasons: > > 1. People upgrading directly from <=PHP 8.1 to PHP 9.0 or people who > have not addressed the deprecations will still get an appropriate > compile-time error message instead of their code suddenly behaving > differently. > 2. We can reuse the syntax at some point without causing another BC break. > > The only advantage of the former approach I can think of is easier (or > rather no) escaping of ${} in strings but this could also be a > drawback considering that it would become unclear what the original > intent of the code was (literal output or string interpolation). > > So unless there are concerns I will amend that in the RFC. > > Regards, > Ilija >
In my reading of the RFC, I assumed the first approach: completely remove the syntax and make "${}" result in the literal string "${}". IMO, this is not an insignificant change to the RFC. I'd like to hear from those who voted on the RFC before you make this change. Cheers, Ben

Mark Randall

4 years ago
On 20/05/2022 10:05, Ilija Tovilo wrote:
> So unless there are concerns I will amend that in the RFC.
Erroring it out makes sense to me. As we don't include any target version specification in PHP files, the safest bet it so prevent the silent change from potentially leaking through the introduction of a parser error.