Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111562 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68351 invoked from network); 16 Aug 2020 20:07:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Aug 2020 20:07:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC91C1804C2 for ; Sun, 16 Aug 2020 12:07:45 -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_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-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) (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 12:07:42 -0700 (PDT) Received: by mail-io1-f50.google.com with SMTP id g14so15625565iom.0 for ; Sun, 16 Aug 2020 12:07:42 -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 :cc; bh=Klleoi/qg+8ROsoxPTKPTm8SXjjAk5oxfcwZg54bSPw=; b=jBm7+Zc5mTF97Au68VzLIo2Zvk/5Omiir8hLZoWMw2Ajpi/0nBvzNnQt7J3OPsYg/F lQicEYryJ92uIo/6ZwJQcar1lgCTA0LvnQPiOk7EAuKDzXjow97TXEcwwWqgpcDMZGER ED07C7vjMOXDExCykzn1IITf1WaLfwPaDnbT1PP5NEBVsz9l/gm0kzxHg4MAf2or3me4 JJWvgkCmiyp7fypI9wRvOm7kyb6pic6D1AqvL7no1vh2hE59TC/g4eBagcQlGAv/R90N nhCyYdRv6Z5kRM9LL5UeNGZNJchrqmY9/9EuifdKyb4zFHbXTFCAnbepGtsUAbB4hB/T i98A== 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:cc; bh=Klleoi/qg+8ROsoxPTKPTm8SXjjAk5oxfcwZg54bSPw=; b=Pcwes6/j4PdjhkzWhqc9Uq3PfG8gqEzX8lLCP9rRSI0YHEl37/l2X96B6xLwTOeSKz NRyqpX72gfYqhxzxW+KzQDeyyayFkk9BdOTtHU4DXbtyUMJ5VuVMnI4O51UWDeJ10BPU B6jtXkByPsiIuOeRyTxSOASu4f1A6x+5C/9VKBYNcE2O5Of9yYo00aEaat2XET5rf5yq emDkymciPxY5tLgJlLuMuWbrLKZ2P6XHdP0TL7SZ7NC49yU0EQH4zs/x6ApZ607Annww 3pbTglok2Q+QBzprpAfWAQxxwzBzJZz1ulNNmXn3wJHkf5w4LrtUeJ/4KaeTbMiEvDIR CWnw== X-Gm-Message-State: AOAM532kVA4oY9WWTgGnummXQ6lXG+QJn1BCAOu2of//f4EZcZTjt0tS /d69owEqTp1JPaG7hwJ7y12wetCikbjvnTHXqHJqTgRaAS4= X-Google-Smtp-Source: ABdhPJzVKoFdJ8pv2ZglPyKwKXs0OxprRM0u34P1e247GO+kWGb8BuwwSIp2q5KwrI5KfzxzY3ei+OQFx3kj9vYuzm4= X-Received: by 2002:a6b:900b:: with SMTP id s11mr9420160iod.83.1597604861569; Sun, 16 Aug 2020 12:07:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 16 Aug 2020 22:07:29 +0300 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000043f19305ad035e0d" Subject: Re: [PHP-DEV] Re: [RFC] Better string interpolation From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000043f19305ad035e0d Content-Type: text/plain; charset="UTF-8" On Sun, Aug 16, 2020, 20:45 Ilija Tovilo wrote: > Hi internals > > > I've been thinking about ways to improve string interpolation. > > Absolutely overwhelmed by the feedback (:P) I've decided to create a small > POC: > > https://github.com/php/php-src/compare/master...iluuu1994:string-interpolation > > The POC uses the following syntax: > echo "Static method call: #{Foo::bar()}"; > > Two questions arose: > > 1. String prefix > > To mitigate the BC break we could require strings that use the new > interpolation to be prefixed. > > // Continues behaving the same > echo "#{Foo::bar()}"; > // Actually makes use of the new interpolation > echo $"#{Foo::bar()}"; > > The main downside is that we have yet another type of string: Simple > quotes with no interpolation, double quotes with *some* interpolation > and fully interpolated strings ($""), each one with their heredoc > counterpart. It's unfortunate but we might prefer this approach to > mitigate the BC break. > > Let me know if you prefer a prefix or no prefix. If the answers are > inconclusive this might become a secondary vote in the RFC. > > 2. Escaping > > It's not quite obvious how escaping should behave. > > $foo = 'foo'; > echo "\#{$foo}"; > > // Could print > //> 1. #foo > // or > //> 2. #{$foo}" > > We could 1. make the backslash escape just the hash and interpret > {$foo} as usual, or 2. make it escape both. > > * Option 1 is more consistent with the rest of the language, backslash > normally just escapes the next character > * Option 1 requires two backslashes when result 2 is desired ("\#{\$foo}") > * Option 2 makes it impossible to achieve result 1 with just braces > and would have to be written as "\##{$foo}" > > Let me know which option makes more sense to you. > > Ilija > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php Hi Ilija, I think this could work and thank you very much for the effort into clarifying the current interpolation situation. Using a prefix for strings that have a saner interpretation reminds me of f-strings in python 3. I would suppose you know about it already but I'll leave a link here anyway: https://www.python.org/dev/peps/pep-0498/ Using $ for the prefix might not be the best option as it would look like this: echo $"next is {$i + 1}"; Maybe f can be used similar with how it is in python but I didn't gave too much thought into it. I'm a casual python user so I need to understand more the history how they got to it. Replying from my phone, sorry if my answer is too short, incomplete and with possible spelling mistakes. Regards, Alex --00000000000043f19305ad035e0d--