Hi Ilija

I 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(),
    );

And this also works with heredoc:

    echo sprintf(
        <<<'HTML'
        <html>
            <head>
                <title>%s</title>
            </head>
        </html>
        HTML,
        htmlspecialchars($title),
    );


-- Arnaud

On jeudi 17 mars 2022 23:27:30 CET Ilija Tovilo wrote:
> Hi everyone
> 
> I'd like to start discussion on a new RFC for arbitrary string
> interpolation. https://wiki.php.net/rfc/arbitrary_string_interpolation
> 
> Let me know what you think.
> 
> Ilija

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

Reply via email to