Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111561 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58537 invoked from network); 16 Aug 2020 18:45:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Aug 2020 18:45:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DCEC31804DB for ; Sun, 16 Aug 2020 10:45:49 -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=-0.7 required=5.0 tests=BAYES_05,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-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 10:45:49 -0700 (PDT) Received: by mail-ej1-f44.google.com with SMTP id c16so15135103ejx.12 for ; Sun, 16 Aug 2020 10:45:49 -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=QcH+vWk+BR0HKJxoS6SYBSOSSY8WT6cY0tHLI951ApA=; b=IOyt27xu05afdw3AQYuRlHktEg+CVRVs/DCIdNK8aCy/EHGbBWrhi05z4WxuZ7eXfU 9Xb/ZaIobDhPE0lOGifrLi/PVb6FXSL1xcUuNW+QOFZv78wMgegk5dVgtK5wEjRMtDvZ ZNzEq8HDcG1rwk7HySkmqZoLkeGoM4z1sMP7tahYasy52KrwDMLur6L4H/dmSOd2gP58 HK2hoJxISyRuVbjcDBMmtOhpz+aLoDj5wjiidtwkltNSUiZHhbVONpc1wWkrtcVqccKO DLL5a9gwvDr9gdE3rcjATlaq8MSlT4FHyeI1hyKWpq7rziop3k6A6Ewb2MJEsmFJzcMa Wzng== 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=QcH+vWk+BR0HKJxoS6SYBSOSSY8WT6cY0tHLI951ApA=; b=qhZ0tDt39PnVuEKS9sB7P+n8U5HlaX5KFz66t5QCca+IBVEG3+qw/CsRbOSfau8IeL SsJIuIwhkr2OrS5gO/Cn8/4Bh7xjS8cKm/r/GLQA+AnjSQjqba/svLiyTyyZFW671SIS xwoz4/mTeRXi/Z4b2ieegsULvHEwLOOziJnz/XeegMS6WyUV3dSKyiiShPpQjxvBb4SM e7AcqFeEWj39wjXg7NAjEYUFL9ubNg+XYAUPxynieWNwSZvgb+sHw964DbvaeimHlu5b IlbDmaIAWMf5NrOzn3ZRIb7RQ6VwmHnSIS569XuSWyh54/yB81Y1tlnD8WP6DxlrKGkm kQtA== X-Gm-Message-State: AOAM532v78CSdZw6Kebdrff03qh/6sCSFlpi55hRNCelVv/niMRcr9dF WyAq/YsZCFVXmhywe/kXch5wL1Pybz/Jbod+LCV32vi443ojDQ== X-Google-Smtp-Source: ABdhPJxWOU0UlPSQXjQKOMdWhQ0saJPJU6uoUvIP2SFEmEBWF0WTQU5uJ02H45dvgxq3MrFyFY2Ioox0ZcIC68+jM3o= X-Received: by 2002:a17:906:5606:: with SMTP id f6mr11418036ejq.297.1597599947773; Sun, 16 Aug 2020 10:45:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 16 Aug 2020 19:45:36 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [RFC] Better string interpolation From: tovilo.ilija@gmail.com (Ilija Tovilo) 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