Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111594 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7738 invoked from network); 17 Aug 2020 18:53:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Aug 2020 18:53:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 55169180511 for ; Mon, 17 Aug 2020 10:54:08 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 17 Aug 2020 10:54:07 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id p24so18760300ejf.13 for ; Mon, 17 Aug 2020 10:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=3isj//KgZVNfYH+4w7zXVhNXnrYYn8ipk4nYgdxLrHQ=; b=L8NEielJQxrzVnFob4Adg74FPrTmN9KWHo9OqcYUqnU7qPMydED2qCcNK0R/u70uqz QpVAJFQqT46WNWN6Qwvw8R/pVOeJ6BL60YVYRPRH6hdPHhudVGH+qZp+GF8i1YbTSJ25 z3rjAd20TApuMyvUEQy79+LWi/qhDhm9lNVdJKqylQ0UNriHyjSeMF5+UJkcFc8T1wlN SDfFqAhd+0w67QoeKtWWaxBPagJhVuu2rQu9f8G3VPKSL2NpWpKFLH36ACIb7y29+Gpm V+MG9pcnt6C9pWS8tijeZ02JiYifdgrlMmv14Euc+34Zq18HHubN8xndKjycdf5U51Pp wf5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=3isj//KgZVNfYH+4w7zXVhNXnrYYn8ipk4nYgdxLrHQ=; b=XogSvhUtFbiH1nrwA0DZwJaWqiinV7bD1Gqp89q0vjaU6PmEUZv1ZdsDkuP/s7nm2N YURyN/v9etn3BR5go91JEfh1x3NW0QpWLXO1jhAG5fNF7Uc2ZHCgQbtJLh7B1ODzfhm/ 7V2Q8fQtxAbW3ENW0zhZxKtZ0uuidDy2D+T8ssGsbDT19f9Nh2TWPMtsG4oBLPFUFSoE t/ExqvaWFKWkFAZu51pTqjrQCY7cu4a1/gPA8xJsfjwE+mB+58TYbfZaQxOesCF0h0Cu l6y6j2YDy96R2LlAO/vLfC6T012sqak1S5sZTPN8WjseM1Q/pN+IDQ4xvg2AV7bHqcIf Gfag== X-Gm-Message-State: AOAM5307y4AVmyWiSa3g9mGlPso/05xA3D4f5/KGNIm3eg/m+2s0fUCp R7ELrCe4Srar1Yo7CF6x5I8XsuPkF7n/wkpgcHVln+ION3BiBQ== X-Google-Smtp-Source: ABdhPJwycdXxLkpUkhjd/CAiL5HjwB2X4U4JJn48bfmmj7+5eWx9mDVYUiWk5zyQKQ1dwGMY1JrTveJeCKxIN+i+3vE= X-Received: by 2002:a17:906:5606:: with SMTP id f6mr15895869ejq.297.1597686846353; Mon, 17 Aug 2020 10:54:06 -0700 (PDT) MIME-Version: 1.0 References: <92f3ee69-7b06-4995-546e-95f0218767bb@gmail.com> In-Reply-To: <92f3ee69-7b06-4995-546e-95f0218767bb@gmail.com> Date: Mon, 17 Aug 2020 19:53:55 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Better string interpolation From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Rowan > On 14/08/2020 17:14, Ilija Tovilo wrote: >> I've been thinking about ways to improve string interpolation. String >> interpolation in PHP is currently pretty limited to say the least. Thanks for your feedback! > we could take the opportunity to bring more features into the mix > > 1) modifiers; e.g. sprintf-style, f"Measure #0.2f{$value}" or > template-style, f"Hello #{$name|escape}" sprintf-style modifiers are an interesting idea. But I'm not sure if there would be a huge advantage over using number_format. I see two issues with template-style filters. 1. The syntax is ambiguous: $name|escape could mean "pass $name to the filter escape" or "bitwise-or $name and the constant escape". We could disambiguate with a different symbol ($name|>escape). 2. This strongly overlaps with the pipe operator (https://wiki.php.net/rfc/pipe-operator-v2). Pipe operators would probably automatically solve this use case (although the given filters still have to be added). > 2) custom rules, like JavaScript's tagged templates [1], e.g. html"Hello > #{$name}" == "Hello " . htmlspecialchars($name) Escaping is a nice idea but I'm not sure we want to go that route. String interpolation is still a bad fit for many templating things, like rendering lists (although possible with implode and array_map) or if statements (although possible with ternary and : ''). For some things you might potentially not expect escaping at all (script tags, style attributes, etc). I'm not completely opposed to the idea but it's not something I'd personally be interested to work on. > If we took JS tagged templates as the inspiration, that would de-sugar > to something like: Interesting, I didn't know about this feature. Honestly, I can't think of many use cases on the spot. It's very possible this is just my limited imagination. Luckily if we decide not adding tagged templates at first there's nothing stopping us from adding them at a later point in time. The same goes with the html tagged templates above. Ilija