On Mon, Mar 21, 2022 at 10:51 AM Rowan Tommins <rowan.coll...@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.