Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108050 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32759 invoked from network); 9 Jan 2020 14:00:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 14:00:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B5EF0180505 for ; Thu, 9 Jan 2020 04:05:43 -0800 (PST) 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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 ; Thu, 9 Jan 2020 04:05:42 -0800 (PST) Received: by mail-lf1-f54.google.com with SMTP id y1so5010096lfb.6 for ; Thu, 09 Jan 2020 04:05:42 -0800 (PST) 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=0Qktw/K6sZ5Q7tJ6WyjALBQCGPEPL7zhJmZQHsXKnpY=; b=ictUtVk1fOlAOXP+iaeQavviEBrMzl8W+JBP7eDf5XQR1UGB32aapjV9KQwwMr9eJH kkJfKjOTE2kI9FQ+1YAMo1Tk/gAO7reAyJ29PnB6CksPshXgWoV7uFrVcloURQoZyb1p 78tMHtCBdhLMW0+H6UDQ4ZrO0Ga4IvbgKEOghkmx66JTiQmSwv4rNDQ4brVYqjS1bgXP TGWytcMkdkB8QX3P3XDRq58VCmwhtCAlwI32EvZ1hN4AjfX2ShRrUxdvTVa3oiiKjdny qF6v6SnXjeV2177J84OwhL2J5YffAvb5jIRioGOo7wXt+Sv6JKnJvaWdQ8lT/55mNEG8 Wv7Q== 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=0Qktw/K6sZ5Q7tJ6WyjALBQCGPEPL7zhJmZQHsXKnpY=; b=CkBz9YAiMvrOZVzWmdeTq3qQBvhSVv72hdXAg6COCH5PikFwlVYxgzccg+kftO+o9d ibK97jR40SZJDo/vrkPzo96rKuRN0RXH92P512eQXXiLPf7BRy1Lf9yozDSjaLBw3U9q eJ+BKNrYRb8QxQMc1Jcz9h+azTxJZJoeWGwuRxUP68Zajr6jRSzKU95O3BphVphYgVJ9 bfnkBfzFKuVzJQaFCJX13vJc6eaMTG+8p6UzYVk/6pwiUC2rVmK8idUa84WCPXTpnhKG 5BTRk1GLzkvQj+brFoBjcjw2/vfjG69YkKVSj9XMsDPqhoXTTNoNGNXAGW1yq4qtI0Sa xBRA== X-Gm-Message-State: APjAAAWdgRayQK14PljtHkrHCYbxgJ+LsIM4EdHo9wi0KKvDWmcIW8mP NhEXE7t3Vuy+nVIKHMUTfsXr/NAJmn9GO1Nv67Q= X-Google-Smtp-Source: APXvYqwer0o3ZRjLJ38PWF2NfrWbCv8VCYraI1qm1ZV40A4CMYYoYpQ/Kl1n4JQQL9LEI/EfHKiwEsQZmPD2pDGSPPU= X-Received: by 2002:a19:5e16:: with SMTP id s22mr6044937lfb.33.1578571538690; Thu, 09 Jan 2020 04:05:38 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 9 Jan 2020 13:05:22 +0100 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d0f80c059bb3d37c" Subject: Re: [PHP-DEV] What to do with "$array[foobar]"? From: nikita.ppv@gmail.com (Nikita Popov) --000000000000d0f80c059bb3d37c Content-Type: text/plain; charset="UTF-8" On Thu, Jan 9, 2020 at 12:12 PM Rowan Tommins wrote: > On Thu, 9 Jan 2020 at 10:48, Nikita Popov wrote: > > > PHP has a couple of legacy string interpolation syntaxes, the most > > egregious being "$array[foobar]". The issue with this syntax is that the > > array key is not quoted, is required to be not quoted and is silently > > accepted. > > > > ... > > > > What do you think about this? I think my personal preference would be > > towards phasing out the syntax entirely: If we're going to make people > > migrate, we can just as well migrate them towards our generic and > preferred > > interpolation syntax. > > > > > Hi Nikita, > > I agree that this syntax is peculiar, and think you're right that the most > consistent way forward is to phase out both "$array[foobar]" and > "$array[0]". > > The biggest problem I see with allowing "$array['foobar']" as an > alternative spelling is that it makes the inconsistent handling of the bare > string even more surprising. Consider these pairs: > That's true, but I think if the "$array[foobar]" syntax is deprecated in the same version that "$array['foobar']" is allowed, we can mostly avoid confusion, because the deprecation message will tell people what's what. [snip] My only hesitation is the usual one for language changes: how much working > code will need to be amended, and how easy is it to identify and correctly > fix that code? > > Since the current syntax isn't ambiguous, it ought in principle to be > possible for a tool to parse source code and identify and fix instances. I > think in cases like this, the upgrading notes should link specifically to > one or more such tools. > > Even with such a tool, it's potentially quite a disruptive change, so we > need to decide how important we think removing this syntax would be. > Yes, reliable auto-upgrade should be possible for this change. I'll also do an analysis run on how common this syntax is in open-source projects later. Assuming that we do want to phase out the "$array[foobar]" interpolation syntax, I think a relevant consideration regarding the upgrade-path is this: Nearly all code-upgrades work by retaining compatibility with the previous PHP version for a while (for open-source code often a long while), so effectively the only possible upgrade pass is to go from "$array[foobar]" to "{$array['foobar']}", as a hypothetical "$array['foobar']" syntax would not be available in the previous PHP version. As such, the question of whether we want to support "$array['foobar']" is not really relevant to the upgrade path, it can only be answered with long-term evolution in mind. That is, as an end result, 10 years down the line, does it make sense for us to support "$array['foobar']" or not? I think the answer to that may well be "yes", because we already support "$string" and "$object->prop", so it is in a way natural that "$array['key']" is also supported, as the last of the "fundamental" variable syntaxes. Finally, if we want to leave things alone, we have the option of just generating a better error message for this. Regards, Nikita --000000000000d0f80c059bb3d37c--