Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117382 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37371 invoked from network); 19 Mar 2022 17:09:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Mar 2022 17:09:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 56D1218053E for ; Sat, 19 Mar 2022 11:35:22 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 ; Sat, 19 Mar 2022 11:35:21 -0700 (PDT) Received: by mail-pl1-f182.google.com with SMTP id d18so9533290plr.6 for ; Sat, 19 Mar 2022 11:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GrL2WoHBr3sBczCZ8f1qkYRNyveqkiAn5CmZSphPQzE=; b=Bgnmt9U/g5ElBw7q43jaHkmhtO8mXgNp6AEg8fpedg6+BQiUaScpxr8asGacITNq2r A+o5/hVOuq3XWRK6HZRhDunqjikE3Sz+ieRxPtViTlBmUD27DX1FNkiiB/kTMXFm0bdz SWi8EkNfIUDguBG9wc79ChvZZmszZvgY9j624cijSmhQKcOrocMJcL6U+Hq6gdshcE+9 3M169BptfWKoLVL5T22fRtpf5dtwfFCKwxmhYrg9/7QFU1SCjmD48c7XvdlM8kdcuwG2 g1ZThV9qIm6JM1yLypZB4/AgnfCsOcfnYtWoCqfs5x5qfMKMvqFTQWUJzX18hvswyn3w VK+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GrL2WoHBr3sBczCZ8f1qkYRNyveqkiAn5CmZSphPQzE=; b=12F/qa9INNEsTrM4VM6b6MjYCXbU6ibwWqB88ug1fgoA+pPK58QHJPGHDbIgXoSEz9 llQebcT6Pk7V9GwkLLZUhAFDWe0txVGzVYBQnYbzzbFkbRh1/jDXVe0jr0bvllbey4fd h8tF74f6pU5ZDAqxr8+Zm69dtPHoNP26Y1hwA5XV15AiXCZR4EI/983HgkPh94/NC+jR DcYjUXZK0Y65R1jEIGJVt/qPPNsXtDX7JUv34jc560+fQS3Wpt/3/1GZruz493dB3D7Y JrXqczC8tOzifCSBoLUGNhJjjBVsZkG8QF39+vuZeEkGeB1lovCP3SLAb2IC47a4kufk zw7Q== X-Gm-Message-State: AOAM532u5FBf5X2CRhxC1Vq0FjiR6vLkDP1Jpuo0fCxLm124RUSmbjAg iqiuHMyCgp1I4GqPUexZXEPi90xbRLbdenlQMuM= X-Google-Smtp-Source: ABdhPJxyS+i6FfKzF2YEMEgMtXP2bXIXGNRz2Sm8Rpr2sKLx02n52wRXfj1fYBUnA5odHd3miH4PkiRKywWwvQfIYc0= X-Received: by 2002:a17:90a:98b:b0:1c6:5824:cc0e with SMTP id 11-20020a17090a098b00b001c65824cc0emr17486580pjo.209.1647714920883; Sat, 19 Mar 2022 11:35:20 -0700 (PDT) MIME-Version: 1.0 References: <4AC60E84-B2AD-43F4-9B72-92604FC7BD41@gmail.com> In-Reply-To: Date: Sat, 19 Mar 2022 19:35:09 +0100 Message-ID: To: Theodore Brown Cc: Chase Peeler , Ilija Tovilo , PHP internals Content-Type: multipart/alternative; boundary="0000000000008cea4605da9686ec" Subject: Re: [PHP-DEV] [RFC][Under discussion] Arbitrary string interpolation From: landers.robert@gmail.com (Robert Landers) --0000000000008cea4605da9686ec Content-Type: text/plain; charset="UTF-8" On Fri, Mar 18, 2022 at 11:01 PM Theodore Brown wrote: > On Fri, Mar 18, 2022 at 09:02 Chase Peeler wrote: > > On Fri, Mar 18, 2022 at 12:49 AM Theodore Brown > wrote: > > > > > > Personally I'm really looking forward to having this functionality. > > > Just a couple days ago I wanted to call a function in an interpolated > > > string, and it was really annoying to have to wrap the function in a > > > closure in order to use it. > > > > > > If this RFC is accepted I'd be able to replace code like this: > > > > > > $name = "Theodore Brown"; > > > $strlen = fn(string $string): int => strlen($string); > > > echo "{$name} has a length of {$strlen($name)}."; > > > > > > with > > > > > > $name = "Theodore Brown"; > > > echo "{$name} has a length of {$:strlen($name)}."; > > > > > > Out of curiosity, why not: > > > > $name = "Theodore Brown"; > > echo "{$name} has a length of ".strlen($name)."."; > > > > or even > > > > $name = "Theodore Brown"; > > $len = strlen($name); > > echo "{$name} has a length of {$len}."; > > Concatenation works fine for a simple example like this, but it can > get a lot messier when there are more than a few embedded variables. > It's particularly an issue with heredoc strings which are far more > cumbersome to concatenate. > > Yes, it's possible to add extra variables before the string like in > your second example, but this feels like unnecessary work, especially > when you already have all the variables you want and just want to > apply a function to them at several places in a template string. > One function that I continuously run into is 'number_format' (and its intl equivalents). It'd be much easier to read "you have {$:number_format(count($items))} remaining" instead of "you have $formatted_count_of_items remaining" > Theodore > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000008cea4605da9686ec--