Hey Ilija. On 25.03.22 15:38, Arnaud Le Blanc wrote:
Hi IlijaI find that sprintf() is easier to read in most cases. One reason for this is that the text is separated from the code. It's also easier to review for humans and linters. The strtoupper example would look like this with sprintf: $world = 'world'; echo sprintf('Hello %s!', strtoupper($world)); Longer examples can be nicely split in multiple lines: echo sprintf( 'Received HTTP status code %d (reason phrase: %s)', $response->getStatusCode(), $response->getReasonPhrase(), );
This technique also allows me to use the original string in translation while still keeping the replacements out of that.
So something like echo sprintf( gettext('Hello %s!'), strtoupper($world) );would easily work and provide the translator only with the string `Hello %s` which is much less to break than `Hello {strtoupper($world)}!`
So for internationalized applications I'd rather keep the sprintf approach than a new string-syntax.
A way to use sprintf in a more out-of-the-box way like in ruby would be awesome! Something like
echo 'Hello %s' % [strtoupper($world)]; or echo 'Hello %{world}' % ['world' => strtoupper($world)]; But I'm absolutely happy with the current sprintf functionality. Just my 0.02€ Cheers Andreas -- ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andr...@heigl.org N 50°22'59.5" E 08°23'58" | | https://andreas.heigl.org | +---------------------------------------------------------------------+ | https://hei.gl/appointmentwithandreas | +---------------------------------------------------------------------+
OpenPGP_0xA8D5437ECE724FE5.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature