Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111564 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76900 invoked from network); 16 Aug 2020 22:33:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Aug 2020 22:33:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 648FA1804C2 for ; Sun, 16 Aug 2020 14:34:00 -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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 ; Sun, 16 Aug 2020 14:33:59 -0700 (PDT) Received: by mail-wm1-f51.google.com with SMTP id g8so11756801wmk.3 for ; Sun, 16 Aug 2020 14:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=nlnwIb5PYxWWe2X8mmFdh7tfgxCuqKMOPm4yWyEjs84=; b=D2MRnG08trtREKka/Xfzk966Q1awCQvEOKeYJcq6DqYJkSJ4GghyKjzm8MjY+LaMDb zPz/cvcZKWPt5LU+Um16fqeQj5oDmAXsYJB5Sx5us4UeOzQvQZy5p3IUJuXtyvf3Qvfd WHXt7RW7vFA7walEJ8FJPPjYgF6n+vH1xE9ttDMgY4EfR1iaWTGcJzqCYP/8e2vtEiSL Ap5tBRs0lrU+ecQSG2EmeFLtz3ovaRvb1YOqZKR+SuohjvL+7RpSrrjv1PmAAmjT7AQh JPk9zpXe80CRLcXOw+15yh9s9ztPYWJtZ78d5uspob5K8RG5YyZtocWjr9F65WIrCT3M 5wRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=nlnwIb5PYxWWe2X8mmFdh7tfgxCuqKMOPm4yWyEjs84=; b=enO2QaH9kwmeS89vy98BFPiwXWKtHOAyikFgtOPjRE/PGbu8bBUZ6sr6wXYCWDO20A hVnrqxHrK35rtIEDLh5QExwBJYhfab1SMYbJm+4ZiSy8KGupWSBoV04pwU2Bw+b0PPeP yYKPtiIXA1uGuW/YeSQTICeNWDb5wjRE5Mme+j0xNQccShPHCcn9HqxM41TiRi04GSLX pl4Zcp3syJI48Hg7EVhb9ynFWoabHlCp5tdQe8jNKhCjmgsdpCiC95Q3oe6V0/BpIJ1e 44XOcLWut9XyOFdPHxvaLruGyFnsKdl5tvYHO+WVtvyD5Nz2Ge4VEa/IsbJoKePVs4e0 NIrg== X-Gm-Message-State: AOAM533QHTjJzhVDyKFR6+T1AxQ0DpsNeUBGiThvF5W20ybdh/CbRCh9 bvVC6BNO8fUCJjqtEmdPG8Kn0tdSQRE= X-Google-Smtp-Source: ABdhPJzFj/6vMsVbZTFHKEnJeJfCOIm83LstuYQKJH6JsyiL3AeyZMb0NGmTs8tc/2i979cjbUmr+w== X-Received: by 2002:a1c:32c3:: with SMTP id y186mr11894425wmy.15.1597613637335; Sun, 16 Aug 2020 14:33:57 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id v12sm28736126wri.47.2020.08.16.14.33.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Aug 2020 14:33:56 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <92f3ee69-7b06-4995-546e-95f0218767bb@gmail.com> Date: Sun, 16 Aug 2020 22:33:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Better string interpolation From: rowan.collins@gmail.com (Rowan Tommins) Hi Ilija, 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 putting together some thoughts on this. My instinct is that rather than having a whole new syntax that's basically a tweak on "${expression}", we could take the opportunity to bring more features into the mix. If you think about it, string interpolation is basically an inline template syntax, so a lot of the features that are useful in template engines would be useful there. Specifically: 1) modifiers; e.g. sprintf-style, f"Measure #0.2f{$value}" or template-style, f"Hello #{$name|escape}" 2) custom rules, like JavaScript's tagged templates [1], e.g. html"Hello #{$name}" == "Hello " . htmlspecialchars($name) Put these together, and you can have variables escaped by default, and opted out via a modifier: $tag = 'h1'; echo html"<#raw{$tag}>Hello #{$_GET['name']}"; If we took JS tagged templates as the inspiration, that would de-sugar to something like: echo render_html_string(     stringParts: [ '<', '>Hello ', '' ],     expressions: [ $tag, $_GET['name'], $tag ],     modifiers: [ ['raw'], [], ['raw'] ] ); It will take a while to figure out the details, but I think a powerful feature like this is more worthy of adding new syntax. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals Regards, -- Rowan Tommins (né Collins) [IMSoP]