Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117373 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51570 invoked from network); 18 Mar 2022 12:43:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Mar 2022 12:43:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 88526180382 for ; Fri, 18 Mar 2022 07:09: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=-1.6 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 94.23.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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 ; Fri, 18 Mar 2022 07:09:07 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 47DD35100317; Fri, 18 Mar 2022 14:09:05 +0000 (UTC) Message-ID: <73550eae-370d-115f-e440-4889e42dbc74@processus.org> Date: Fri, 18 Mar 2022 15:09:03 +0100 MIME-Version: 1.0 Content-Language: en-US To: Chase Peeler , Theodore Brown Cc: Tobias Nyholm , Ilija Tovilo , PHP internals References: <4AC60E84-B2AD-43F4-9B72-92604FC7BD41@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC][Under discussion] Arbitrary string interpolation From: pierre-php@processus.org (Pierre) Le 18/03/2022 à 15:02, Chase Peeler a écrit : > On Fri, Mar 18, 2022 at 12:49 AM Theodore Brown > wrote: > >> On Thu, Mar 17, 2022 at 5:40 PM Tobias Nyholm >> wrote: >> >>> On Thu, 17 Mar 2022, 23:27 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. >>> That is a cool idea. >>> But I am not a big fan of having code in strings. >>> Wouldn’t this open the door to all kinds of new attacks? >> Do you have an example of a new kind of attack this would allow? >> The proposal doesn't enable interpolation of strings coming from >> a database or user input - it only applies to string literals >> directly in PHP code. >> >> 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}."; I guess it's a matter of taste and convention. Sometime, it make sense and it's just easier to just use string interpolation (for example with multiline templates). Regards, -- Pierre