Re: [RFC][Under discussion] Arbitrary string interpolation

From: Date: Mon, 21 Mar 2022 10:27:56 +0000
Subject: Re: [RFC][Under discussion] Arbitrary string interpolation
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-117389@lists.php.net to get a copy of this message
On Mon, Mar 21, 2022 at 10:51 AM Rowan Tommins <rowan.collins@gmail.com> wrote: > On 20/03/2022 13:39, Rowan Tommins wrote: > > Using a second colon would make ternary expressions slightly awkward; > > C# handles this by requiring them to be parenthesised, so "{$:( $test > > ? $x : $y )}" would be valid but "{$:$test ? $x : $y}" would not; we > > could use some other delimiter, but they'd probably all need something > > similar. > > > Thinking about it, a second colon might also cause problems for > expressions like "{$: Foo::bar() }", so since we have multiple symbols > at the start anyway, how about a prefixed formatting argument, e.g. > "{$%10.3f: $x }" > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > The downside of a prefix is that it isn't backwards compatible. You could use # in a suffix so if you need to write backwards compatible code, you can. So maybe: echo "{$x#10.3f}"; which can be written like this in backwards compatible code: echo "{$x#10.3f }"; It isn't pretty, but it's better than a parse error and things like Rector could do this automatically.

« previous php.internals (#117389) next »