On 21/03/2022 10:27, Robert Landers wrote:
> 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
> }";


That's a neat trick, although I'm surprised comments are allowed in that position given expressions in general aren't.

I think being a syntax error in previous versions is a good thing though; falling back to ignoring the formatting specifier could result in unexpected behaviour, maybe even leaking data that the formatting was intended to hide, and projects which need to support multiple PHP versions are more likely to simply use sprintf() to get the same output on all versions.

I was also deliberately pairing it with the arbitrary expression syntax as one new feature, so that we don't have so many combinations to explain to new users ("$x", "{$x}", "{$: $x}", "{$x#10.3f}", "{$: $x #10.3f}")

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to