# Removal of ${} string interpolation in PHP 9

- Thread: https://externals.io/message/117760
- Original archive: https://news-web.php.net/php.internals/117760
- Started by Ilija Tovilo on 2022-05-20T09:05:00+00:00
- Messages: 7
- RFC: Removal of ${} string interpolation (Accepted) — https://externals.io/rfc/deprecate_dollar_brace_string_interpolation.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #117760 — Ilija Tovilo — 2022-05-20T09:05:00+00:00

URL: https://externals.io/message/117760#117760

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

---

## #117763 — Ben Ramsey — 2022-05-22T02:26:01+00:00

URL: https://externals.io/message/117760#117763 · In reply to: #117760

> 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

---

## #117764 — Peter Bowyer — 2022-05-22T07:09:01+00:00

URL: https://externals.io/message/117760#117764

> In my reading of the RFC, I assumed the first approach: completely
> remove the syntax and make "${}" result in the literal string "${}".
>

I voted Yes on this RFC, and that was my expectation.

Otherwise we haven't entirely removed it, and left a footgun for people
with a new special case that isn't variable interpolation and isn't normal
characters in a string.

Peter

---

## #117766 — Mark Randall — 2022-05-22T22:46:39+00:00

URL: https://externals.io/message/117760#117766 · In reply to: #117760

> 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.

---

## #117768 — Robert Landers — 2022-05-23T11:59:21+00:00

URL: https://externals.io/message/117760#117768

>
> 
> > […]
>
> 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.
>
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>


Ilija,

It might be a good idea to do up another RFC to make it easy to vote.
I suspect it won't be unanimous.

---

## #117785 — Michael Morris — 2022-05-24T20:36:50+00:00

URL: https://externals.io/message/117760#117785 · In reply to: #117768

I can understand removing this feature since it is a bit confusing, but are
there any plans to replace it - say with the template literal syntax of
JavaScript? For those needing to refactor having something to switch to
would be preferable than having the feature dropped.  Or does PHP have some
goofy use for backtick that would prevent this from happening?

On Mon, May 23, 2022 at 6:59 AM Robert Landers <landers.robert@gmail.com>
wrote:

> 
> > […]
>
>
> Ilija,
>
> It might be a good idea to do up another RFC to make it easy to vote.
> I suspect it won't be unanimous.
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #117786 — Rowan Tommins — 2022-05-24T22:26:22+00:00

URL: https://externals.io/message/117760#117786 · In reply to: #117785

> I can understand removing this feature since it is a bit confusing, but are
> there any plans to replace it - say with the template literal syntax of
> JavaScript? For those needing to refactor having something to switch to
> would be preferable than having the feature dropped.  Or does PHP have some
> goofy use for backtick that would prevent this from happening?


There already is something to switch to - the "{$foo}" syntax (which is 
staying) supports everything the "${foo}" syntax does and more. There 
has been intermittent talk of adding "even better" interpolation of some 
sort, but without consensus on exactly what the features should be - 
search on https://externals.io/ to see previous threads.

(And yes, PHP does have a "goofy" use for backtick, inherited from Perl, 
as an alias for shell_exec. But that's not really relevant because there 
are plenty of programming languages which have multiple quoting styles 
without using it, mostly by adding a prefix, e.g. Python's f"...".)

Regards,

-- 
Rowan Tommins
[IMSoP]
