Re: String interpolation shortcomings
| From: | ilija dot tovilo at me dot com | Date: | Tue, 11 Jul 2017 19:35:31 +0000 |
| Subject: | Re: String interpolation shortcomings | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99843@lists.php.net to get a copy of this message | ||
Oops, I actually meant to suggest the syntax
“Hello \{world()}” (note: curlies
instead of parens) to be closer to the original syntax.
Regards,
Ilija
On 11 Jul 2017, 21:10 +0200, ilija.tovilo@me.com, wrote:
> Hi everyone
>
> String interpolations are a great feature. They make your code more readable and can reduce the
> number of allocations PHP has to make.
>
> Unfortunately, PHP is very restrictive in what kind of expressions string interpolation
> accepts. The only time you can actually use it is if your expression starts with the
> $ symbol. You cannot use it for:
>
> - Function calls
> - Infix expressions
> - Constants or class constants
> - Instantiations
> - Expressions in parentheses
>
> Or anything else that doesn’t begin with the $ symbol.
>
> Even more unfortunate is that ${foo()} is equivalent to
> {$foo()} which means we cannot simply extend the current syntax to
> support all expressions. Of course, we could deprecate the ${foo()}
> syntax and reintroduce it with a different semantic meaning after some time but this is far from
> satisfying.
>
> There is also the possibility of introducing new syntax for string interpolation and
> deprecating the old one after a transition period (e.g. `”Hello \(world())”).
>
> Does anyone think this is worth fixing?
>
>