Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108049 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24547 invoked from network); 9 Jan 2020 13:06:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 13:06:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 690D8180531 for ; Thu, 9 Jan 2020 03:12:03 -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-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (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 03:12:02 -0800 (PST) Received: by mail-io1-f51.google.com with SMTP id z193so6698622iof.1 for ; Thu, 09 Jan 2020 03:12:02 -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; bh=Db2WDTpP30BrdZBkWPzquttnQbNd5Jl69eO6IiSdjVA=; b=P0cEPgypSXZU8lNSOikR3YEeRo2eqlc7NNMJiEcSYTF+pRCqtlUd9bEyg8zuANpIET U3bREjg5bYX+05nMSDurmlPi4sZUmM7QElOYK2rPVXtIZp/ocmZRFpRUCfcBuMBHnw9C 1TEm5T4Rx0vd7PAae+PHdb0CvG1rQo1MTWfpKOpgTiLM7SVRPfKR9Y8H3BTBKJuuPXoM XduXteumPJ7B0yQOEAaOOQowl5ZJ8EvYPMLT/o2ie9N1wmOxRo5BD/LHWQRYKKjM445f WQr93Ladr1phmAcWiXfHmdvRiyKO0SGZwL4DmGFUCd5WQYVW3cKtsQFR457reLv6EcYe JCVg== 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=Db2WDTpP30BrdZBkWPzquttnQbNd5Jl69eO6IiSdjVA=; b=cU1ynNL6KURvcbSAeht/PNwa7TnZVsqn3mT24DCiFV8ZMV5ZdDimE05L+xgfUixzyh TbQqeSpulNSFIu/nEZ8pjxNxCantTmyEoMxlyH0VjVG1GZEWka0M/wSZUqbMhhK6aszT gm9NfbtipmesAYGWLmj93WN4ZQ8LqTRqit8crDLUjvOqcYMluhCN/epCqODUlF1f8B5C w6vjnAgIpzLEk+niZ0PB+vzLOpJMpTe7bFXsQ4Jxagf5uOz7FRaW4GIIrfoCdFmt9ont lJx3LlftYUAkPJNzfzu77PyBFdkXcI8QqF8QzjjGJIcfDwGdK6Pz+3GCxOX6lW87qsLs YeTg== X-Gm-Message-State: APjAAAXhHBsubjVEkXyN+Na0RX26T+EoDyMKLUbZQR3oJiWTBu7YP+0Z nOxtVDHA4tcBzNIpBAqsEFa9WhH6swmIMfo5+zoVh1sc X-Google-Smtp-Source: APXvYqyEcR9COoARLrwdSJ0DDN+6KwkXJkjHAkR3NpbUdLBhEzKsbMgFQXgfAY7zo1LBWnbvoStjO4T34in26UmFjhM= X-Received: by 2002:a5e:9902:: with SMTP id t2mr7020633ioj.120.1578568321304; Thu, 09 Jan 2020 03:12:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 9 Jan 2020 11:11:50 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000000b8f32059bb31400" Subject: Re: [PHP-DEV] What to do with "$array[foobar]"? From: rowan.collins@gmail.com (Rowan Tommins) --0000000000000b8f32059bb31400 Content-Type: text/plain; charset="UTF-8" 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: const DEBUG='yes' $array = [ 'DEBUG' => 'blah blah blah', 'yes' => 'yes yes yes' ]; // Normal PHP code echo $array['DEBUG']; // quoted string as key - echoes blah blah blah echo $array[DEBUG]; // constant as key - echoes yes yes yes // Properly delimited string interpolation echo "{$array['DEBUG']}"; // quoted string as key inside string interpolation - echoes blah blah blah echo "{$array[DEBUG]}"; // constant as key inside string interpolation - echoes yes yes yes // Shorthand string interpolation; only the second form currently compiles echo "$array['DEBUG']"; // quoted string as key inside string interpolation - echoes blah blah blah echo "$array[DEBUG]"; // looks like a constant, but acts like a string! - echoes blah blah blah 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. Regards, -- Rowan Tommins [IMSoP] --0000000000000b8f32059bb31400--