Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108046 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15204 invoked from network); 9 Jan 2020 12:42:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jan 2020 12:42:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 11E2A1804D1 for ; Thu, 9 Jan 2020 02:48:02 -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-f44.google.com (mail-lf1-f44.google.com [209.85.167.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 ; Thu, 9 Jan 2020 02:48:01 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id n12so4856967lfe.3 for ; Thu, 09 Jan 2020 02:48:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=8Pl9ECe6KbihB15TpuwtgvNyBVCTynVteQ0vojjX2Pc=; b=gqi0tuA7bPOKqUWye0JbTxWhwC0lfvMFtYcDHtMNqkwUVbNcnImfGm3Q8wP30E8h7/ YSNPqqy4Q+iEe1u4W0hE2agZyqId3pMfHWtIW88XeK3SJS6rZT400AO/PtHd9S/YE8xS mpNhTTW175UKqGBgJpwyLypCcFZU4ChDO2GzRXFT3JO9s6Wr6KPAUAY+HOfuRd9fpABF krabCc+KAisojCTc5LxzJdeGz0cIDIvPvsbBASqdlTuho7WNBoEVehdfFAWj/8Uqy1YF Q/HKbkJaJir29dJTvPiYLax0x0/kl6wr6VB1niWcqeQhp9GTEgp4Kyvl0LunJqKO0CDN 5VVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=8Pl9ECe6KbihB15TpuwtgvNyBVCTynVteQ0vojjX2Pc=; b=MqKPXnOwtf1eQZLS4rZlsZFO3pM/wX4LPs4YW/zCaXE5SZ3i71v/Y8amTufz3B1lIO V2towX697yUdtDhqzFsi90mlbMfNR/veC71dAiiVb0X65qRN/18rJrH9ENOq56OBXMM0 vgtAsdKjcK8dFn7ObdUsmDBnMUWFOJCDBV8DeH1qOSKpfIeJiewUunGAdvRebAH9gIQA 7Zd2tF9sGrhHAMgXnXR9ZfmT37E9cxOJSmJYOjKd2uBUqbLqaqRYSpOUkL9CwvzKvhWb wC/eNvnMmozXO2x5eUTLAuhnPMI1f+lBY4N49jLGx60XOXnsefwRSgSqRVZ61+9yEjRI yiNA== X-Gm-Message-State: APjAAAXaTir0qUNSXy7Qmn389/i6cELDntseu82vpuLv2YQ8UCpl11Jt ZjW8SRVYS1N36sLrDfBX3KtbEV1HIaOdRVXlPBglGwjGE20= X-Google-Smtp-Source: APXvYqzBvxATblyC7Bi0IBC8ZhlVr45pAbow8g6vimudLOebYav9IdOt9ceTHCyNgyXoPoKRuyoPSOBxWpLrBuFzX6w= X-Received: by 2002:a19:c205:: with SMTP id l5mr5771101lfc.159.1578566879767; Thu, 09 Jan 2020 02:47:59 -0800 (PST) MIME-Version: 1.0 Date: Thu, 9 Jan 2020 11:47:44 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000001f7d99059bb2beeb" Subject: What to do with "$array[foobar]"? From: nikita.ppv@gmail.com (Nikita Popov) --0000000000001f7d99059bb2beeb Content-Type: text/plain; charset="UTF-8" Hi internals, 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. We've been fighting back against unquoted strings for a long time, culminating with $array[foobar] in normal code becoming an Error exception in PHP 8, as the string fallback for unknown constants has been removed. In this context, it is particularly weird that "$array[foobar]" continues to be silently allowed, and the more expected form "$array['foobar']" yields an inscrutable error message: > Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) I think there's two ways to address this. One is to deprecate and eventually remove the non-wrapped array interpolation syntax entirely, requiring people to use the generic "{$array['foobar']}" syntax instead. For the sake of consistency, I think this would also include deprecating the "$array[0]" variant. The other is to add support for "$array['foobar']" and "$array[some(complex(expression()))]" in general, and only deprecate the "$array[foobar]" syntax. 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. Regards, Nikita --0000000000001f7d99059bb2beeb--